C++,从文件读取数据

来源:百度知道 编辑:UC知道 时间:2024/05/31 20:07:11
文件格式如下:
杜菲 1 2 3 4 5 6 7 8 9 10 11 12
王智平 1 2 3 4 5 6 7 8 9 10 11 12
张力强 1 2 3 4 5 6 7 8 9 10 11 12
陈钢 1 2 3 4 5 6 7 8 9 10 11 12
周小龙 1 2 3 4 5 6 7 8 9 10 11 12
黄雄 1 2 3 4 5 6 7 8 9 10 11 12
刘学龙 1 2 3 4 5 6 7 8 9 10 11 12
李新影 1 2 3 4 5 6 7 8 9 10 11 12
吴琳 1 2 3 4 5 6 7 8 9 10 11 12
王爽 1 2 3 4 5 6 7 8 9 10 11 12
这个行数是不固定的。。可以增加名字
我从文件中读取每一个名字。要保存下来。后面的数字也要保存下来。
如何做到。
希望高人们。帮帮。我想了N久。。没想出来。。行数。如果增加了。用动态数组去创建。。
但是赋值出错。郁闷中
#include <iostream.h>
#include <stdio.h>
#include <fstream.h>
#include <cstdlib>
#include <string.h>
#include <iomanip.h>

void main()
{

fstream out_stream;
ifstream in_stream;

int i=10;
char *p=new char[i];

char temp[7];
int Count=0;

in_stream.open("test.txt");

if(in_stream.fail())
{
cout<<"打开文件失败"<&

可以用链表来做。

可以定义一个结构体或类 存数据 先数一下有多少组
用文件长度除组数就知道 一组的长度 组数变了 文件长度随着变 动态规划的时候只要知道现在是多少组就OK了