c++未定义标识符 "getline",没有与这些操作数"<<"匹配的运算符不知为何无法运行,很迷求解答,谢谢!
#include<iostream>#include<string.h>usingnamespacestd;structJG{stringname;stringword;...
#include<iostream>
#include<string.h>
using namespace std;
struct JG
{
string name;
string word;
int password;
};
int main()
{
JG mm = {};
cout << "Enter your name please!\n";
getline(cin, mm.name);
cout << "This is your name:" << mm.name << endl;
cout << "Enter your code!\n";
cin >> mm.word;
mm.password = mm.word[0] + mm.word[1] * mm.word[2] * mm.word[3] - 1000000;
cout << "This is your password,please keep it in mind!" << endl << mm.password << endl;
cin.get();
} 展开
#include<string.h>
using namespace std;
struct JG
{
string name;
string word;
int password;
};
int main()
{
JG mm = {};
cout << "Enter your name please!\n";
getline(cin, mm.name);
cout << "This is your name:" << mm.name << endl;
cout << "Enter your code!\n";
cin >> mm.word;
mm.password = mm.word[0] + mm.word[1] * mm.word[2] * mm.word[3] - 1000000;
cout << "This is your password,please keep it in mind!" << endl << mm.password << endl;
cin.get();
} 展开
1个回答
展开全部
代码没什么问题啊
在Gcc下是可以编译通过的
是不是你的编译器有问题
改成这样 应该更通用一些。
#include<iostream>
#include<string.h>
using namespace std;
struct JG
{
char name[20];
char word[40];
int password;
};
int main()
{
JG mm = {};
cout << "Enter your name please!\n";
cin.getline( mm.name, 20);
cout << "This is your name:" << mm.name << endl;
cout << "Enter your code!\n";
cin >> mm.word;
mm.password = mm.word[0] + mm.word[1] * mm.word[2] * mm.word[3] - 1000000;
cout << "This is your password,please keep it in mind!" << endl << mm.password << endl;
cin.get();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询