第1个回答 2010-04-15
#include <iostream>
#include<vector>
using namespace std;
FILE* in;//定义文件变量:in
vector<int> a;
int main(){
in=fopen("c:\ccp.txt","r");//以只读方式打开C盘下的ccp.txt文件
int temp;
while(fscanf(in,"%d",&temp)!=EOF){
//读取ccp里面的int数值,直到文件末尾
a.push_back(temp);//将读取的数值插入到a中
}
for(temp=a.size()-1;temp>=0;temp--)
cout<<a.at(temp);//测试
fclose(in);//关闭文件
return 0;
}
第2个回答 2010-04-15
读取一个数字之后,就读取一个字符,判断这个字符是不是一个换行符,如果是换行符,说明这一行数字读取完了,开始处理.