C++中类中cout使用+出错

C++语言 码拜 8年前 (2016-04-28) 1220次浏览
#include “stdafx.h”
#include <iostream>
using namespace std;
class Studentid
{
int id;
public:
Studentid()
{
id = ++id;
}
};
class Student
{
string name;
Studentid sid;
public:
Student(string n = “noname”)
{
cout << “Construing student ” +  n + “\n”;
name = n;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
解决方案

14

加上头文件#include<string>就行了

7

标准库没有重载+(string s) 这种类型吧,<<(string s) 也没有

6

你没包含#include <string>头文件
string类型运算符的重载在<string>头文件中

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C++中类中cout使用+出错
喜欢 (0)
[1034331897@qq.com]
分享 (0)