getline:找不到标识符

Ada*_*yga 3 c++ getline visual-studio-2013

我有问题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;

}    
Run Code Online (Sandbox Code Playgroud)

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

Lig*_*ica 9

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

#include <string>
Run Code Online (Sandbox Code Playgroud)


Pro*_*ogo 6

这应该解决这个问题:

#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;
}
Run Code Online (Sandbox Code Playgroud)


aar*_*van 5

#include <string>
Run Code Online (Sandbox Code Playgroud)

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


Abh*_*pta 4

你需要使用

#include "string"
Run Code Online (Sandbox Code Playgroud)

阅读:std::getline

  • 不是“string”,而是“&lt;string&gt;”,我也遇到了这个问题,并且使用了[cppreference](http://en.cppreference.com/w/cpp/string/basic_string/getline) (7认同)