我必须从控制台读取整行并将其存储到 std::string
和 char
数组中,
例如
"Hi this is balaji"
现在我必须读取上面的字符串并将其存储到 string
中。我尝试使用 getline()
函数。
最佳答案
尝试:
#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
}
关于c++ - 如何从控制台读取行并将其存储到 C++ 中的字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759894/