I have to read a whole line from the console and store it into a std::string
and a char
array,
e.g.
"Hi this is balaji"
Now I开发者_C百科 have to read the above string and store it into string
. I tried it using the getline()
function.
Try:
#include <string>
#include <iostream>
int main()
{
std::string line;
std::getline(std::cin, line); // read a line from std::cin into line
std::cout << "Your Line Was (" << line << ")\n";
std::getline(std::cin, line); // Waits for the user to hit enter before closing the program
}
Maybe there's something wrong with how you use cin.getline()?
cin.getline (name,256);
C++ refence for getline()
Maybe
string a;
cin >> a;
cout << a << endl;
Or something like that?
精彩评论