CString Object in a console application...
-
Hi, i am working in console application in VC++(visual studio 2005). i am having a problem while using CString. i have mentioned sample code below. #include "stdafx.h" #include "server1.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { CString str; str="IP conneted" printf("%s",str); cout<<str; } return nRetCode; } while executing the code.. i get printed only first letter(I) of str. so please help me.. is there any header or setting should i change in the visual studio environment?
-
Hi, i am working in console application in VC++(visual studio 2005). i am having a problem while using CString. i have mentioned sample code below. #include "stdafx.h" #include "server1.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { CString str; str="IP conneted" printf("%s",str); cout<<str; } return nRetCode; } while executing the code.. i get printed only first letter(I) of str. so please help me.. is there any header or setting should i change in the visual studio environment?
Check if the following works:
CStringA str; str = "IP conneted"; printf("%s", str); cout<< str;
-
Hi, i am working in console application in VC++(visual studio 2005). i am having a problem while using CString. i have mentioned sample code below. #include "stdafx.h" #include "server1.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { CString str; str="IP conneted" printf("%s",str); cout<<str; } return nRetCode; } while executing the code.. i get printed only first letter(I) of str. so please help me.. is there any header or setting should i change in the visual studio environment?
Try it :)
...
#ifdef _UNICODE
wcout << LPCTSTR(str);
#else
cout << LPCTSTR(str);
#endifvirtual void BeHappy() = 0;
-
Check if the following works:
CStringA str; str = "IP conneted"; printf("%s", str); cout<< str;
CStringA?
Величие не Бога может быть недооценена.
-
CStringA?
Величие не Бога может быть недооценена.
Yes, for UNICODE settings CString get replaced to CStringW and for Multi-Byte it gets replaced to CStringA. You can check atlstr.h header.
-
Hi, i am working in console application in VC++(visual studio 2005). i am having a problem while using CString. i have mentioned sample code below. #include "stdafx.h" #include "server1.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { CString str; str="IP conneted" printf("%s",str); cout<<str; } return nRetCode; } while executing the code.. i get printed only first letter(I) of str. so please help me.. is there any header or setting should i change in the visual studio environment?
Probably it is a UNICODE issue. Try changing
rrthangavel wrote:
printf("%s",str);
with
printf("%S",str);
to check it. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, i am working in console application in VC++(visual studio 2005). i am having a problem while using CString. i have mentioned sample code below. #include "stdafx.h" #include "server1.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { CString str; str="IP conneted" printf("%s",str); cout<<str; } return nRetCode; } while executing the code.. i get printed only first letter(I) of str. so please help me.. is there any header or setting should i change in the visual studio environment?
CString str; str="IP conneted"//assigning Multibyte to Unicode variable, i miss a 'c' :rolleyes: printf("%s",str);//non-sense RTFM cout<<str; // sending Unicode to Multibyte console :confused::confused::confused: i would write wcout<<TEXT("IP connected") :-O
Press F1 for help or google it. Greetings from Germany