ファイルから 2D ベクトルへの読み込みで問題が発生しています。私は c++ が初めてで、コードに問題が見られません。
ファイルはこのパターンに従います。
5
0 0 0 0 1
0 0 0 1 0
0 0 0 1 1
0 0 1 0 0
...
それを読むための私のアルゴリズム...
void Similarity::readData(Scanner& inStream){
dataLength = inStream.nextInt();
while(inStream.hasNext()){
vector<int> temp;
int tempInt = 0;
for(int i = 0; i < dataLength; ++i){
tempInt = inStream.nextInt();
temp.push_back(tempInt);
temp.clear();
}
theData.push_back(temp);
theData.clear();
}
}
そして、それを印刷する私のアルゴリズム。
string Similarity::toString(){
string result = "";
for(int i = 0; i < theData.size(); ++i){
for(int j = 0; j < dataLength; ++j){
result += convertInt(theData[i][j]);
}
result += "\n";
}
return result;
}
string Similarity::convertInt(int number){
stringstream s;
s << number;
return s.str();
}
toString からの出力はありません。作業が必要なのは readData ですか、それとも toString ですか?
ありがとうございました。