C++ getline:未找到标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27755191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:52:07  来源:igfitidea点击:

getline: identifier not found

c++visual-studio-2013getline

提问by Adam Fatyga

I have problem with getline().
I tried many examples and read other solutions, but that didn't solve my problem. I still have info 'getline: identifier not found'. I included <stdio.h> <tchar.h> <iostream> <conio.h> <stdlib.h> <fstream>and still nothing.

我有问题getline()
我尝试了很多示例并阅读了其他解决方案,但这并没有解决我的问题。我还有资料'getline: identifier not found'。我包括 <stdio.h> <tchar.h> <iostream> <conio.h> <stdlib.h> <fstream>但仍然没有。

#include "stdafx.h"

using namespace std;

int main(int argc, _TCHAR* argv[])

{

 string line;
 getline(cin, line);
 cout << "You entered: " << line << endl;

}    

What do I need to do now? I use Win7 64bit, MSVS2013.

我现在需要做什么?我使用的是 Win7 64 位,MSVS2013。

回答by Lightness Races in Orbit

Get used to simply reading the documentationfor the language features that you use.
cppreference is quite clear that std::getlinemay found in string.

习惯于简单地阅读您使用的语言功能的文档
cppreference 很清楚,std::getline可以在string.

#include <string>

回答by Progo

This should fix that:

这应该解决这个问题:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, _TCHAR* argv[]){
   string line;
   getline(cin, line);
   cout << "You entered: " << line << endl;
}

回答by Abhishek Gupta

回答by aaronvan

#include <string>

Incidentally, "Murach's C++ Programming" textbook incorrectly states that getline() is in the iostream header (p. 71) which may lead to some confusion.

顺便说一句,“Murach 的 C++ 编程”教科书错误地指出 getline() 位于 iostream 标头(第 71 页)中,这可能会导致一些混淆。