【发布时间】:2014-12-29 12:16:09
【问题描述】:
我正在读取一个包含 25 个数字的 txt 文件,每行 5 个。
1 8 5 7 9
2 4 6 8 10
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
我的代码是:
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
#include <stdio.h>
using namespace std;
int main()
{
string myFile, mystring;
string DIR;
string extension;
int total = 0;
int number_of_lines = 0;
string line;
extension = ".txt";
DIR = "H:\\Year2\\C++\\EE273\\Week5\\";
cout << "Enter the name of the file ";
cin >> myFile;
myFile = DIR + myFile + extension;
ifstream inFile;
inFile.open(myFile.c_str());
if (!inFile) {
cout <<"Error opening file"<<myFile<<endl;
return -1;
}
while (!inFile.eof()){
int m=5;
int n=5;
int Array[i][j];
for (int i=0;i<5;i++){
for (int j=0; j<5; j++){
inFile >> Array[i][j];
for(int row=0;row<5;row++){
for (int column=0;column<5;column++){
cout<<Array[i][j];
}}}}
}
//cout<<mystring<<endl;
inFile.close();
system("PAUSE");
}
我得到的错误是:
error C2065 for i and j: identifier not declared.
我不明白问题出在哪里。
提前谢谢你。
【问题讨论】:
标签: c++ arrays file numbers ifstream