getline(cin, str) not working

getline(cin, str) not working

本文关键字:not working str cin getline      更新时间:2023-10-16

我的程序提示用户输入文件名,然后我使用getline将其放入字符串变量中。getline没有将用户的输入存储到文件名中。为什么?

int main() {
string fileName;
cout << "==============================================================n"
<< "|        Welcome to the Automatic Maze Path Finder!      |n"
<< "=============================================================n"
<< "nEnter the name of the Maze configuration file: ";
getline(cin, fileName);

此外,当使用cout语句进行测试时,它会将输出放到当前命令行上。例如:user@computer:~$//程序输出出于某种原因而出现在此处?它为什么这么做??

std::cin表示标准用户输入,std::cout表示标准输出。如果您希望将输入/输出从不同的内容中读取/写入,则必须使用该系统(例如std:fstream)。

你的代码对我来说似乎很好。