[英]getlines undefined in iostream in C++
这是我的代码:出于某种原因, getline
表示未定义。 我的教授告诉我,我可能使用的是旧版本的 C++,但我不知道如何检查它。
我正在使用 Visual Studio Ultimate 2013。请救救我。
提前致谢。
顺便说一句:我不介意与getline
无关的代码中的任何错误。 代码不完整,但当getline
未定义时我无法测试它。
#include <iostream>
using namespace std;
int main()
{
string concatenatedLines;
getline(cin, concatenatedLines);
if (!cin)
{ // C++ can overwrite conversion operator... cin is being converter into a boolean operator. It is FALSE if you attempted to read and there's nothing there.
return 1;
}
// START OF MISSING CODE *-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=
//
int numberOfLines = 1;
int stat = 0;
string line;
string space = " ";
while (stat == 0)
{
getline(cin, line);
if (!cin) stat = 1;
else{
concatenatedLines = line + space + concatenatedLines;
numberOfLines++;
}
}
//
// END OF MISSING CODE *-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=
cout << concatenatedLines << endl;
//endl = end of the line - declared in the standart library
cout << concatenatedLines << endl;
return 0;
}
您还需要包含<string>
标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.