Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString Object in a console application...

CString Object in a console application...

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++csharpvisual-studiodebugging
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rrthangavel
    wrote on last edited by
    #1

    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?

    K E CPalliniC K 4 Replies Last reply
    0
    • R rrthangavel

      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?

      K Offline
      K Offline
      KingsGambit
      wrote on last edited by
      #2

      Check if the following works: CStringA str; str = "IP conneted"; printf("%s", str); cout<< str;

      A 1 Reply Last reply
      0
      • R rrthangavel

        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?

        E Offline
        E Offline
        Eugen Podsypalnikov
        wrote on last edited by
        #3

        Try it :)

        ...
        #ifdef _UNICODE
        wcout << LPCTSTR(str);
        #else
        cout << LPCTSTR(str);
        #endif

        virtual void BeHappy() = 0;

        1 Reply Last reply
        0
        • K KingsGambit

          Check if the following works: CStringA str; str = "IP conneted"; printf("%s", str); cout<< str;

          A Offline
          A Offline
          Adam Roderick J
          wrote on last edited by
          #4

          CStringA?

          Величие не Бога может быть недооценена.

          K 1 Reply Last reply
          0
          • A Adam Roderick J

            CStringA?

            Величие не Бога может быть недооценена.

            K Offline
            K Offline
            KingsGambit
            wrote on last edited by
            #5

            Yes, for UNICODE settings CString get replaced to CStringW and for Multi-Byte it gets replaced to CStringA. You can check atlstr.h header.

            1 Reply Last reply
            0
            • R rrthangavel

              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?

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              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]

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • R rrthangavel

                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?

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups