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 to const *char or clr

CString to const *char or clr

Scheduled Pinned Locked Moved C / C++ / MFC
c++dotnethelptutorialquestion
5 Posts 4 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.
  • S Offline
    S Offline
    Star09
    wrote on last edited by
    #1

    Hello, Can someone please tell me how to convert from CString to const* char? I used the following from msdn website: // Convert to a char* const size_t newsize = 100; char nstring[newsize]; strcpy_s(nstring, orig); strcat_s(nstring, " (char *)"); cout << nstring << endl; But it requires that I compile with clr. When I do that, my classx.cpp (all my class function) are considered errors. When I don't modify the property of my solution to clr, I still get two errors: fatal error C1190: managed targeted code requires a '/clr' option Is there any other way to convert without using clr? Thank you. --Star

    C M P 3 Replies Last reply
    0
    • S Star09

      Hello, Can someone please tell me how to convert from CString to const* char? I used the following from msdn website: // Convert to a char* const size_t newsize = 100; char nstring[newsize]; strcpy_s(nstring, orig); strcat_s(nstring, " (char *)"); cout << nstring << endl; But it requires that I compile with clr. When I do that, my classx.cpp (all my class function) are considered errors. When I don't modify the property of my solution to clr, I still get two errors: fatal error C1190: managed targeted code requires a '/clr' option Is there any other way to convert without using clr? Thank you. --Star

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This is not clr code, I can't imagine how it gives you this error. The CString class has a GetBuffer method that returns a char *. Not sure if it is char or TCHAR, but so long as you're not building Unicode, they are the same.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • S Star09

        Hello, Can someone please tell me how to convert from CString to const* char? I used the following from msdn website: // Convert to a char* const size_t newsize = 100; char nstring[newsize]; strcpy_s(nstring, orig); strcat_s(nstring, " (char *)"); cout << nstring << endl; But it requires that I compile with clr. When I do that, my classx.cpp (all my class function) are considered errors. When I don't modify the property of my solution to clr, I still get two errors: fatal error C1190: managed targeted code requires a '/clr' option Is there any other way to convert without using clr? Thank you. --Star

        M Offline
        M Offline
        Manoj Kumar Rai
        wrote on last edited by
        #3

        Hi, Why dont you use the "strcpy" and "strcat" respectivily instead of using "strcpy_s" and "strcat_s". Since the later 2 functions have more securuty enchancements you problem could be related with that.

        Manoj Never Give up

        P 1 Reply Last reply
        0
        • S Star09

          Hello, Can someone please tell me how to convert from CString to const* char? I used the following from msdn website: // Convert to a char* const size_t newsize = 100; char nstring[newsize]; strcpy_s(nstring, orig); strcat_s(nstring, " (char *)"); cout << nstring << endl; But it requires that I compile with clr. When I do that, my classx.cpp (all my class function) are considered errors. When I don't modify the property of my solution to clr, I still get two errors: fatal error C1190: managed targeted code requires a '/clr' option Is there any other way to convert without using clr? Thank you. --Star

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          In addition to previous reply, have a look at CString::operator LPCTSTR. Again, it depends on project settings.


          Prasad MS MVP -  VC++

          1 Reply Last reply
          0
          • M Manoj Kumar Rai

            Hi, Why dont you use the "strcpy" and "strcat" respectivily instead of using "strcpy_s" and "strcat_s". Since the later 2 functions have more securuty enchancements you problem could be related with that.

            Manoj Never Give up

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #5

            manojkumarrai wrote:

            Why dont you use the "strcpy" and "strcat" respectivily instead of using "strcpy_s" and "strcat_s".

            I guess, one should always use enhanced versions of functions. Isn't it ?

            manojkumarrai wrote:

            have more securuty enchancements you problem could be related with that.

            :confused:. How could be that ?


            Prasad MS MVP -  VC++

            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