0
我試圖從標有{1 ... 9}或X的文件讀取輸入。我需要分開這些值並將它們正確存儲在向量中。我使用的是「sstringstream」幫我這樣做:發生在if語句,當在「輸入」的整數它不執行if語句Isstringstream不適用於整數
void myclass::Initialize(ifstream &file_name)
{
string input;
int value;
//Initialize the values in the matrix from the values given
//in the input file, replace x with a 0
for(int i = 0; i < 9; i++)
{
for(int j = 0; j < 9; j++)
{
//Read the input from the file and determine
//if the entry is an "int" or "x"
file_name >> input;
cout << input << endl;
istringstream(input);
if(input >> value) //PROBLEM HERE!!
{
Matrix[i][j] = value;
cout << "Debug: Check for values in matrix: " << Matrix[i][j] << endl;
}
else
Matrix[i][j] = 0;
}
}
cout << "The values in Matrix after initialization: " << endl;
Print_result();
}
的問題。我不確定它爲什麼不起作用。
你說得對,我忘了「是」。非常感謝! – Josh