作者INsoarDEEP (green)
看板EE_DSnP
標題[問題] 關於上課的例子
時間Mon Oct 8 20:27:28 2007
我嘗試著打一個像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
1F:推 AlanLee76083:要先宣告 string myname 10/08 23:03
2F:推 INsoarDEEP:呃...宣告字串要用什麼符號呢? 10/08 23:17
3F:推 AlanLee76083:#include<string> 10/08 23:23
4F:推 INsoarDEEP:還是COMPILE錯誤阿...OTZ 10/08 23:32
5F:推 ilway25:你拿CD中的檔案compile & 比較一下看看 10/08 23:39
6F:推 ric2k1:It's will be easier if you can post the complete code 10/09 00:38
7F:→ ric2k1:and the error message... 10/09 00:39
※ 編輯: INsoarDEEP 來自: 140.112.236.234 (10/09 17:07)
8F:推 INsoarDEEP:已經加上程式碼了,煩請各位指點一下,感謝! 10/09 17:07
9F:推 timrau:getline(cin, string myname) -> getline(cin, myname) 10/09 23:40
10F:→ timrau:sayhello.function1(string myname)也是把string拿掉 10/09 23:41