获取线函数未定义错误。无法在字符串中保存可验证的内容

getline function is not defined error.Can't hold the veriable in string

本文关键字:保存 字符串 可验证 函数 未定义 错误 获取      更新时间:2023-10-16
#include <iostream>
#include <string>
using namespace std;
int main()
{
string message;
cout << "Type your message: ";
cin.ignore();
getline(cin, message);
return 0;
}

它给出了getline函数未定义的错误。

我只想将写入的字符串保存在可验证的消息中。

这是图片

"...string, stdafx.h 和 iostream...">"stdafx.h"必须是第一行。编译器将忽略它上面的所有内容(<string>将不包括在内,因此编译器将抱怨:getline not found(。

我不知道你想做什么,但下面的代码将编译并运行:

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string message;
cout << "Type your message: ";
cin.ignore();
getline( cin, message );
return 0;
}