I'm trying to find how to convert a char array into a std::string, but I can't find anything to do this.
If it is impossible, could you explain me how can I read an std::string but by scanf() and gets() I can't.
Best regards.
I'm trying to find how to convert a char array into a std::string, but I can't find anything to do this.
If it is impossible, could you explain me how can I read an std::string but by scanf() and gets() I can't.
Best regards.
The simplest way of making a string from a character array is using a constructor that takes a pointer and the length, like this:
char charArray[] = {'w', 'x', 'y', 'z'};
std:string s(&charArray[1], 2); // s is "xy"
// ^ ^
// | |
// Pointer to the |
// starting position Length