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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what is the diff between String and string?

what is the diff between String and string?

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++help
4 Posts 2 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.
  • M Offline
    M Offline
    mitil20390482304
    wrote on last edited by
    #1

    is there a way to convert String to string ? I am using c++.net forms in the form.h file when i try to get the name of a file from the texbox and open it , i get an error. it sayd it cant convert the typr _wchar to char !!! i used ifstream infile; infile.open(fileName);

    C 1 Reply Last reply
    0
    • M mitil20390482304

      is there a way to convert String to string ? I am using c++.net forms in the form.h file when i try to get the name of a file from the texbox and open it , i get an error. it sayd it cant convert the typr _wchar to char !!! i used ifstream infile; infile.open(fileName);

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

      wchar is a wide string. you need to use wstring instead of string. You can also use _bstr_t to convert automagically between them, I think it's in comutils.h. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      M 1 Reply Last reply
      0
      • C Christian Graus

        wchar is a wide string. you need to use wstring instead of string. You can also use _bstr_t to convert automagically between them, I think it's in comutils.h. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        M Offline
        M Offline
        mitil20390482304
        wrote on last edited by
        #3

        thanks christian can you write it as a code i am not so sure how to use _bstr_t eg. char me; Char you; is it then right to say me = _bstr_t(you) and can it be used for char arrays as well?

        C 1 Reply Last reply
        0
        • M mitil20390482304

          thanks christian can you write it as a code i am not so sure how to use _bstr_t eg. char me; Char you; is it then right to say me = _bstr_t(you) and can it be used for char arrays as well?

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

          _bstr_t is a string wrapper that internally contains both a wide and a narrow string. It would treat a char as a char array of one. I would use it like this: some COM function(BSTR myBSTR, BSTR * returnBSTR) { std::string s(dynamic_cast_bstr_t(myBSTR)); ... use the string *returnBSTR = _bstr_t(s.c_str()).detach(); } The syntax is probably horribly wrong, it's 12 months since I did any serious C++, but certainly that is mostly right. My string is being passed a char * in it's constructor, which comes from a temporarily created _bstr_t. The cast to char* may not be necessary, the point is that _bstr_t will construct itself from the BSTR ( wide string ) and then it's operator char* will perform the conversion for you. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          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