getline: identifier not found

2020-07-11 08:39发布

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.

4条回答
走好不送
2楼-- · 2020-07-11 08:46

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>
查看更多
乱世女痞
3楼-- · 2020-07-11 08:46
混吃等死
4楼-- · 2020-07-11 09:05

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;
}
查看更多
祖国的老花朵
5楼-- · 2020-07-11 09:05
#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.

查看更多
登录 后发表回答