xcode中的C ++输入和输出流错误

时间:2016-11-21 14:23:39

标签: c++ xcode std cout cin

所以我试图用C ++构建一个简单的程序,我是C ++的初学者,所以请尽量保持简单!

这是我的代码:

#include <iostream>

using namespace std;

int main()
{
char lastName[30];
int previousBalance;
int payments;
int charges;

cout >> "Please enter your last name:\n";
cin << lastName;

cout >> "Please enter your previous balance:\n";
cin << previousBalance;

cout >> "Please enter payments since previous balance:\n";
cin << payments;

cout >> "Please enter your charges since previous balance:\n";
cin << charges;

return 0;
}

XCode为每个cin和cout语句提供了相同的错误:

二进制表达式的无效操作数('ostream'(又名'basic_ostream')和'const char *')

二进制表达式的无效操作数('istream'(又名'basic_istream')和'char *')

我在代码中做错了什么,或者我在XCode中做错了什么?

1 个答案:

答案 0 :(得分:1)

改变你的

cout >> "Please enter your last name:\n";
cin << lastName;

cout << "Please enter your last name:\n";
cin >> lastName;

其他人一样

cout >>调用operator>>函数,它不接受字符串。 同样适用于cin,这就是为什么会出现错误