次のような.txtファイルからint番号で配列を作成する単純なプログラム
2 3
5 7
4 2
y x
y x
...
したがって、これは単純なnx2です(nは無制限の行にすることができます)。次に、新しいファイルにその配列を入力します(後で、この配列を面白いアルゴリズムで編集するためのコードを追加します)。
私はそれを書いた:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(){
ofstream outFile;
ofstream fout;
fout.open("krol.txt");
int l=0;
int i=2;
char ch;
while (fout.good()){
if (fout >> ch=='\n') l++;
}
fout.close();
fout.open("krol.txt");
int temp[l][2];
int savel=l;
l=0;
while (fout >> (temp[l][i])){
i++;
if(i==2){
i=0; l++;
}
}
outFile.open("save.txt");
for (int i=0, j=0;j<savel;i++){
if (i==2) {
i=0; j++;
}
outFile << temp[j][i];
}
system("PAUSE");
return 0;
}
しかし、それは戻ります:
13 15 C:\Users\Filip\Dysk Google\Infa\krol.cpp [Error] no match for 'operator>>' in 'fout >> ch'
20 29 C:\Users\Filip\Dysk Google\Infa\krol.cpp [Error] no match for 'operator>>' in 'fout >> temp[l][i]'
何か案は?