作者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