C++编程。怎么从文本文件中读取数据并存入二维数组

文本文件中有三列,第一列的数作为行,第二列的数作为列,第三列的数作为对应行列的数值,请问C++编程怎么实现它?

2 1 1
10 1 1

要使A[2][1]=1,A[10][1]=1

我的两列数据
 0     3470    
 1     3482    
 2     3497    
 3     3513    
 4     3527    
 5     3529    
 6     3556    
 7     3579    
 8     3580 
一共1080行 
    
 #include<iostream>
#include<fstream> 
#include <string>
#include <stdio.h>
using namespace std; 
int main(){
int x[1080][2];
int j,i,n=0;
FILE *fp;
fp=fopen("ss.csv","r");
if(!feof(fp)){
cout << " open file" << endl;
while(1){
fscanf(fp,"%x,%x",&x[n][0],&x[n][1]);
if (feof(fp))break;
n++;}
}else
cout << "Cannot open file" << endl;
fclose(fp);
printf("n=%d\n",n);
for (j=0;j<n;j++){
for (i=0;i<2;i++)
printf("%x ",x[j][i]);
printf("\n");
}
system("pause");
return 0;
}
输出

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-04-18
可以先行读取,在将每行分解读取,最后将每行的3个元素存入3个数组追问

可以给一下参考代码吗,谢谢。。

本回答被网友采纳
第2个回答  2016-04-18
这么麻烦,拿nitepad复制第一列,拷入excel然后转置成行,在把另外两列复制进制表格就成了
第3个回答  2016-04-19
还是比较模糊,手机拍照不行
相似回答