C++ Isstringstream不适用于整数
我正在尝试从标有{1…9}或X的文件中读取输入。我需要分离这些值并将它们正确地存储在向量中。我正在使用“sstringstream”来帮助我做到这一点:C++ Isstringstream不适用于整数,c++,string,file,vector,io,C++,String,File,Vector,Io,我正在尝试从标有{1…9}或X的文件中读取输入。我需要分离这些值并将它们正确地存储在向量中。我正在使用“sstringstream”来帮助我做到这一点: void myclass::Initialize(ifstream &file_name) { string input; int value; //Initialize the values in the matrix from the values given //in the input file,
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();
}
void myclass::Initialize(ifstream和文件名)
{
字符串输入;
int值;
//根据给定的值初始化矩阵中的值
//在输入文件中,将x替换为0
对于(int i=0;i<9;i++)
{
对于(int j=0;j<9;j++)
{
//从文件中读取输入并确定
//如果条目是“int”或“x”
文件名>>输入;
cout value)//这里有问题!!
{
矩阵[i][j]=值;
你实际上没有使用istringstream。我想你在寻找类似的东西
..
istringstream is(input);
if (is >> value)
{
...
其中'is'是从字符串“input”创建的istringstream。您实际上并没有使用istringstream。我想您正在寻找类似于
..
istringstream is(input);
if (is >> value)
{
...
其中“is”是从字符串“input”创建的istringstream