<分区>
我正在使用 visual studio 2012 编写普通的 c++,但对于我声明的变量,我一直收到此错误。
1>c:\users\joe\skydrive\documents\c++\consoleapplication2\matracies 1.cpp(182): error C2065: 'file' : undeclared identifier
1>c:\users\joe\skydrive\documents\c++\consoleapplication2\matracies 1.cpp(184): error C2065: 'file' : undeclared identifier
这是我收到错误的函数。
void WriteMatrix(vector<vector<float>> Matrix, float row, float col, int choice)
{
if (choice == 1)
{
ofstream file("MultiplyMatrix.txt", ios::app);
}
else if (choice == 2)
{
ofstream file("AddMatrix.txt", ios::app);
}
else if (choice == 3)
{
ofstream file("AddMatrix.txt", ios::app);
}
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
float temp = Matrix[i][j];
file<<temp<<" ";
}
file<<endl;
}
file<<endl;
file.close();
}