getline: identifier not found

二次信任 提交于 2019-12-06 08:27:30

问题


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.

#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.


回答1:


Get used to simply reading the documentation for the language features that you use.
cppreference is quite clear that std::getline may found in string.

#include <string>



回答2:


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;
}



回答3:


you need to use

#include "string"

Read: http://en.cppreference.com/w/cpp/string/basic_string/getline




回答4:


#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.



来源:https://stackoverflow.com/questions/27755191/getline-identifier-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!