看板 EE_DSnP 關於我們 聯絡資訊
我嘗試著打一個像Fig3.3的程式,但是在getline ( cin, myname )的部分compile失敗, 它說我的"myname" is expected primary-expression,這是什麼意思呢? (不知道這問題會不會問的不好...) #include <iostream> #include <string> using namespace std; class MyClass {public : void function1(string myname) { cout << " Nice to meet you ," << myname << '.' << endl; } }; int main() { cout << "Input your name."; string myname; MyClass sayhello; getline( cin, string myname ); sayhello.function1(string myname); system ("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.236.234
AlanLee76083:要先宣告 string myname 10/08 23:03
INsoarDEEP:呃...宣告字串要用什麼符號呢? 10/08 23:17
AlanLee76083:#include<string> 10/08 23:23
INsoarDEEP:還是COMPILE錯誤阿...OTZ 10/08 23:32
ilway25:你拿CD中的檔案compile & 比較一下看看 10/08 23:39
ric2k1:It's will be easier if you can post the complete code 10/09 00:38
ric2k1:and the error message... 10/09 00:39
※ 編輯: INsoarDEEP 來自: 140.112.236.234 (10/09 17:07)
INsoarDEEP:已經加上程式碼了,煩請各位指點一下,感謝! 10/09 17:07
timrau:getline(cin, string myname) -> getline(cin, myname) 10/09 23:40
timrau:sayhello.function1(string myname)也是把string拿掉 10/09 23:41