C++ getline

我是初学者,可能说的不是专业术语,请谅解。。。
我编的这个程序要是银行存款问题,所以要用int,那std::getline应该属于哪个函数头?我看例子里getline都是在#include<string>,如果用#include<math.h>也不对。
快快有人回答我啊,我是自学。。。。

#include <iostream>//这个必须要的
#include <string>//不用一定会出错的

using namespace std;
/*namespace,是指标识符的各种可见范围。
C++标准程序库中的所有标识符都被定义于一个名为std的namespace中。
很多语句作用域的文件夹,没这不行*/

int main()
{
string line;
//int i;//不能用其他类型,试试就知道了

while( getline( cin, line ) )
cout << line << endl;
//while( getline( cin, i ) )
//cout << i << endl;

return 0;
}

或者你要用于char的话:

#include <iostream>

using namespace std;

int main()
{
char name[ 5 ];
char dessert[ 5 ];

cin.getline( name, 5 );//输入不能超过五个字符哦
cin.getline( dessert, 5 );//输入不能超过五个字符哦

cout << name << endl;
cout << dessert << endl;

//system( "pause" );系统暂停
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-15
#include<iostream>
using namespace std;

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网