[問題] string所遇到的問題
使用VC 6 XP 32bit SP2
以下是我有問題的程式碼(已經刪除和簡化過)
由於不長我就直接貼上來了
#include <iostream.h>
#include <string>
using namespace std;
class monster
{
public:
int hp;
int lv;
string name;
monster(int _hp,int _lv,string _name)
{
hp=_hp;
lv=_lv;
name=_name;
}
};
void main()
{
monster object1(100,10,"001怪物");
cout<<object1.lv<<endl;
cout<<object1.hp<<endl;
//cout<<object1.name<<endl; <---問題所在
}
簡單來說就是有一個怪物class 裡面有lv,hp和名字
class是我朋友做的(再合寫一個遊戲) 然後我複製過來套用
就會產生問題 但是我朋友不會= =
以下為問題敘述
建立一個物件名為object1
cout object1.lv跟object1.hp都沒問題
但是加上object1.name就編譯時產生錯誤??
查很多資料都還是不知道該如何解決@@? 麻煩各位幫我看一下
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.47.72.22
→
12/20 02:04, , 1F
12/20 02:04, 1F
→
12/20 02:05, , 2F
12/20 02:05, 2F
→
12/20 02:11, , 3F
12/20 02:11, 3F
error C2679: binary '<<' : no operator defined which takes a right-hand
operand of type 'class std::basic_string<char,struct
std::char_traits<char>,class std::allo
cator<char> >' (or there is no acceptable conversion)
Error executing cl.exe.
※ 編輯: advance760 來自: 114.47.72.22 (12/20 02:20)
推
12/20 02:36, , 4F
12/20 02:36, 4F
→
12/20 02:41, , 5F
12/20 02:41, 5F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):