How to converts name[20] to string

This is a discussion on How to converts name[20] to string within the C++ Programming forums, part of the General Programming Boards category; Please can anyone assist. I read from a file a name which is held in a name[20]. I then need ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    4

    Question How to converts name[20] to string

    Please can anyone assist. I read from a file a name which is held in a name[20]. I then need to pass this to a function that takes a string datatype.

    I need no conversion in Visual STudio but it seems I do in G++.

    Any suggestions?

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    You shoudn't have to, if name is a char[20].

    std::string s = name; //This will work
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    4
    Thanks, I'll try and see what happens.
    Mike

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21