'operator<<' C++ 不匹配
no match for 'operator<<' C++
我的程序不会 运行 我收到一条错误消息:
`error: no match for 'operator<<' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and '<unresolved overloaded function type>')|`
在cout << address, " ", street << endl;
行
我使用的是 VS2017,但中途切换到 CodeBlocks
我有 Windows 10 Pro Ryzen 5 2400G, 1060 6gb 16gb 内存
这是我的程序:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name, city, state, road, country, street;
int address;
cout << "Enter your: Name\n";
cin >> name;
cout << "Enter your Street\n";
cin >> street;
cout << "Enter your: Address\n";
cin >> address;
cout << "Enter your:\n City\n";
cin >> city;
cout << "Enter your: Province/State\n";
cin >> state;
cout << "Enter your: Country\n";
cin >> country;
//Output
cout << name << endl;
cout << address, " ", street << endl;
cout << city, " ", province, " ", country;
}
提前致谢!
你的语法有误。您不能像那样使用 ,
将参数链接到 cout
。相反:
cout << address << " " << street << endl;
cout << city << " " << province << " " << country;
你的最后两个陈述语法不正确。它们应该如下 -
cout << address<<" "<<street << endl;
cout << city<< " "<< province<<" "<< country;
您可能正在尝试在 C++ 中使用类似 python 的东西。但显然那是行不通的。每次你只需要继续做 cout<< variable1 << " " << variable2<< " ";
。这就是链接在 C++ 中的工作方式。 没有shorthand那个
希望这能解决您的问题!
我的程序不会 运行 我收到一条错误消息:
`error: no match for 'operator<<' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and '<unresolved overloaded function type>')|`
在cout << address, " ", street << endl;
行
我使用的是 VS2017,但中途切换到 CodeBlocks
我有 Windows 10 Pro Ryzen 5 2400G, 1060 6gb 16gb 内存
这是我的程序:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name, city, state, road, country, street;
int address;
cout << "Enter your: Name\n";
cin >> name;
cout << "Enter your Street\n";
cin >> street;
cout << "Enter your: Address\n";
cin >> address;
cout << "Enter your:\n City\n";
cin >> city;
cout << "Enter your: Province/State\n";
cin >> state;
cout << "Enter your: Country\n";
cin >> country;
//Output
cout << name << endl;
cout << address, " ", street << endl;
cout << city, " ", province, " ", country;
}
提前致谢!
你的语法有误。您不能像那样使用 ,
将参数链接到 cout
。相反:
cout << address << " " << street << endl;
cout << city << " " << province << " " << country;
你的最后两个陈述语法不正确。它们应该如下 -
cout << address<<" "<<street << endl;
cout << city<< " "<< province<<" "<< country;
您可能正在尝试在 C++ 中使用类似 python 的东西。但显然那是行不通的。每次你只需要继续做 cout<< variable1 << " " << variable2<< " ";
。这就是链接在 C++ 中的工作方式。 没有shorthand那个
希望这能解决您的问题!