首页 > 解决方案 > '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 ram

这是我的程序:

#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;
}

提前致谢!

标签: c++windowscodeblocks

解决方案


你的语法是错误的。您不能使用,链接参数来cout喜欢那样。而是这样做:

cout << address << " " << street << endl;
cout << city << " " << province << " " << country;

推荐阅读