Sudoku 용 프로그램을 작성하려고합니다. 스도쿠는 제 입력 파일을 위해 잘 실행됩니다. 하지만 컴파일러에서 파일을 입력하는 몇 가지 변경을하고 싶습니다. 'open'을 호출 할 때 일치하는 멤버 함수가없는 것과 같은 에러를 잡는다. 내 문제는 I/O 파일이라고 생각하기 때문에 이것은 내 프로그램의 일부일뿐입니다. 어떤 도움을 주셔서 감사합니다! 감사합니다!Sudoku에서 파일을 여는 방법은 무엇입니까?
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char filename;
ifstream myfile;
//int row,column;
int choice;
cout << "Enter the desired sudoku 4 for (4x4) or 9 for (9x9) : \n";
cin >> choice;
if(choice == 9) {
for(int row = 0; row < 9; row++) // iterating the loop to assign initial dummy values
{
for(int column = 0; column < 9; column++)
{
sudoku[row][column] = 0; // assigining zeros
}
}
cout << "Enter the filename:" << endl;
cin >> filename;
myfile.open(filename); // opening the file mentioned
cout << "The values in the file are :" << endl;
if (myfile.is_open())
{
while (!myfile.eof())
{
for(int row = 0; row < 9; row++) // iterating the loope to get the values form the file
{
for(int column = 0; column < 9; column++)
{
myfile >> sudoku[row][column]; // assigning the values to the grid
cout << sudoku[row][column] << endl; // printing the grid
}
}
}
}
myfile.close(); // closing the file
solvesudoku(0,0);//We start solving the sudoku.
}
else if(choice == 4) {
for(int row = 0; row < 4; row++) // iterating the loop to assign initial dummy values
{
for(int column = 0; column < 4; column++)
{
sudoku1[row][column] = 0; // assigining zeros
}
}
cout << "Enter the filename:" << endl;
cin >> filename;
myfile.open(filename); // opening the file mentioned
cout << "The values in the file are :" << endl;
if (myfile.is_open())
{
while (!myfile.eof())
{
for(int row = 0; row < 4; row++) // iterating the loope to get the values form the file
{
for(int column = 0; column < 4; column++)
{
myfile >> sudoku1[row][column]; // assigning the values to the grid
cout << sudoku1[row][column] << endl; // printing the grid
}
}
}
}
myfile.close(); // closing the file
solsudoku(0,0);//We start solving the sudoku.
}
else {
cout << "Invalid Choice..!!!";
}
return 0;
}
당신은'#include'입니까? –
Assimilater
@Assimilater : 예, 있습니다. – pansoh
http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong 그리고 오류가 무엇입니까? – kfsone