与 std 中的“operator<<”不匹配

用户11347373

我刚开始学习 C++,这个测试似乎是一个好主意,所以我尝试这样做,似乎没有用,而且(对我来说)这真的没有意义。

#include <iostream>

using namespace std;

int myNum = 5;               // Integer (whole number without decimals)
double myFloatNum = 5.32543;    // Floating point number (with decimals)
char myLetter = 'H';         // Character
string myText = "test text: test";     // String (text)
bool myBoolean = true;            // Boolean (true or false)

int main() {

    cout << myNum << endl;
    cin >> myNum >> endl;

    cout << myFloatNum << endl;
    cin >> myFloatNum >> endl;

    cout << myLetter << endl;
    cin >> myLetter >> endl;

    cout << myText << endl;
    cin >> myText >> endl;

    cout << myBoolean << endl;
    cin >> myBoolean >> endl;

    return 0;

}
萨马拉斯

没有意义的cin东西进入endlcin是一个从中获取数据的流,但endl正如@arsdever 所评论的那样,这是结束行的事情。

只需删除它,您的代码就会编译:

#include <iostream>
#include <string>    // You forgot to include that header, for using std::string
using namespace std;

int myNum = 5;
double myFloatNum = 5.32543;
char myLetter = 'H';
string myText = "test text: test";
bool myBoolean = true;

int main() {

    cout << myNum << endl;
    cin >> myNum;

    cout << myFloatNum << endl;
    cin >> myFloatNum;

    cout << myLetter << endl;
    cin >> myLetter;

    cout << myText << endl;
    cin >> myText;

    cout << myBoolean << endl;
    cin >> myBoolean;

    return 0;
}

虽然,您可能希望首先读取用户的输入,然后打印它。现在,您打印由您预定义的变量值(然后打印行尾),然后从用户那里读取该特定变量的输入。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

'std :: operator中的'operator <<'不匹配

错误:std :: cin的“ operator >>”不匹配

'std :: operator ...中的'operator <'不匹配。这是什么意思?

std::regex 不匹配

std :: cin中的运算符>>不匹配

'operator[]' 不匹配(操作数类型是 'std::unique_ptr<std::vector<int> >' 和 'int')

'operator + ='不匹配(操作数类型为'std :: basic_ostream <char>'和'int')

使用std :: chrono :: high_resolution_clock时,“ operator =“不匹配

'operator ='不匹配(操作数类型为'std :: vector <int>'和'int'

为什么在使用`std :: find`时错误显示'operator =='不匹配?

排序功能中“ operator =”不匹配

与“ operator =”不匹配

错误:“operator[]”不匹配?

与“ operator <<”不匹配

错误:不匹配'operator >>'(操作数类型为'std :: istream'{aka'std :: basic_istream <char>'}和'const int')|

与'operator ='不匹配(操作数类型为'__gnu_cxx :: __ alloc_traits <std :: allocator <std :: vector <int>>>

'operator+' 不匹配(操作数类型是 'std::vector' 和 'std::vector::size_type {aka long unsigned int}')

错误:'operator>>' 不匹配(操作数类型为 'std::istream' {aka 'std::basic_istream<char>'} 和 'Oper')

'operator <<'不匹配(操作数类型为'std :: ostream'{aka'std :: basic_ostream <char>'}和'const std :: type_index')

错误:与“ operator +”不匹配(操作数类型为“ std :: __ cxx11 :: list <int>”和“ int”)|

错误:“operator<<”不匹配(操作数类型为“std::basic_ostream<char>”和“<unresolved重载函数类型>”)

如何理解C ++错误,“不匹配'operator =='(操作数类型为'std :: pair'和'const int')”?

解决错误:与 operator[] 不匹配

std向量与运算符不匹配==

c ++ std regexp为什么不匹配?

错误:'operator[]' 不匹配(操作数类型是 'std::map<std::__cxx11::basic_string<char>, int>' 和 'char')

出于某种原因,我不断收到此错误:“operator>>”不匹配(操作数类型为“std::istream”{aka 'std::basic_istream<char>'}

使用累加时,C ++中的operator +不匹配

如何修复 C++ 中的“与 operator+ 不匹配”?