c++语言用文件输入数值,C++中将Vector中的数据存入文件

本文讨论了一个C++程序在尝试将Vector中的数据存入文件时遇到的问题。主要问题在于使用char类型存储姓名导致输入失败,以及写文件的for循环逻辑错误。通过将char改为string,修正循环逻辑并添加flush操作,成功解决了文件无内容的问题。
摘要由CSDN通过智能技术生成

代码如下,输出的文件中没有内容……不知道为嘛……哪里有问题么?为什么?要怎么修改?

#include

#include

#include

#include

#include

using namespace std;

class Student_Info{

public:

vector name;

vector score;

};

int main()

{

Student_Info S;

char name;

double score;

vector::const_iterator n;

vector::const_iterator s;

ofstream OutFile("students.txt", ios::out|ios::binary );

while (cin >> name >> score){

S.name.push_back(name);

S.score.push_back(score);

}

for (n = S.name.begin(); n != S.name.end(); n++){

for (s = S.score.begin(); s != S.score.end(); s++){

OutFile <

}

}

OutFile.close();

system("pause");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值