获取线:未找到标识符

getline: identifier not found

本文关键字:标识符 获取      更新时间:2023-10-16

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

我现在需要做什么?

我使用 Windows 7 64 位和 Visual Studio 2013。

习惯于简单地阅读您使用的语言功能的文档。
CPP偏好很清楚,std::getline可能会在string中找到。

#include <string>

这应该可以解决这个问题:

#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;
}
#include <string>

顺便说一下,"Murach's C++ Programming"教科书错误地指出getline()在iostream标头中(第71页),这可能会导致一些混淆。

你需要使用

#include "string"

阅读: 标准::获取线