How do you create a string from a character array?
Better yet, how do you read from a line from a file and then assign that line to a string? The getline method from the ifstream class requires a *char as it is...
Printable View
How do you create a string from a character array?
Better yet, how do you read from a line from a file and then assign that line to a string? The getline method from the ifstream class requires a *char as it is...
Code:char *line;
//manipulate line
std::string s = line;
//...
std::string s= ...;
s = line;
//or
s += line;
//or
s.assign(line);
Use the getline method that works with strings:Best part - you don't have to worry about the length of the input.Code:#include <iostream>
#include <string>
int main()
{
std::string input;
std::getline(std::cin, input);
std::cout << input << std::endl;
}