关于文件输入的问题
#include <iostream>#include <fstream>
struct donation
{
char name;
int amount;
};
int main()
{
int a;
std::ifstream read;
read.open("data.txt");
if (!read.is_open())
{
std::cout << "打不开文件" << std::endl;
}
read >> a;
read.get();
std::cout << "你要创建" << a << "个结构";
donation *p = new donation ;
for (int b=0;b<a;b++)
{
read.getline(p.name,30);
read >> p.amount;
std::cout << "已写入" << p.name << std::endl
read.get();
}
std::cout << "finished!!" << std::endl ;
std::cout << "现在为您打印姓名和捐款" << std::endl;
for (int b=0;b<a;b++)
{
std::cout << p.name;
std::cout << p.amount;
}
return 0;
}
怎么回事!? 流处理格式不全? 已解决,解决方法是更改文件换行符的类型要用UNIX的
页:
[1]