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.
习惯于简单地阅读您使用的语言功能的文档.
cppreference很明显,std::getline可能会在string.
#include <string>
Run Code Online (Sandbox Code Playgroud)
这应该解决这个问题:
#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)
#include <string>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,“Murach 的 C++ 编程”教科书错误地指出 getline() 位于 iostream 标头中(第 71 页),这可能会导致一些混乱。
你需要使用
#include "string"
Run Code Online (Sandbox Code Playgroud)
阅读:std::getline
| 归档时间: |
|
| 查看次数: |
47213 次 |
| 最近记录: |