【发布时间】:2012-09-03 16:43:18
【问题描述】:
代码如下:
代码:
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
int id;
char name[50];
ifstream myfile("savingaccount.txt"); //open the file
myfile >> id;
myfile.getline(name , 255 , '\n'); //read name **second line of the file
cout << id ;
cout << "\n" << name << endl; //Error part : only print out partial name
return 0;
}
文件内容:
1800567
何瑞张
21
女
马来西亚人
012-4998192
20 , Lorong 13 , Taman Patani Janam
马六甲
双溪独龙
问题:
1.)我希望 getline 将名称读入 char 数组名称,然后我可以打印出名称,事情不是得到全名,我只得到部分名称,为什么会这样?
谢谢!
【问题讨论】:
-
是完全相同的代码吗?另外,它打印什么?也发布输出。