本文整理汇总了C++中FileIO::SetFileName方法的典型用法代码示例。如果您正苦于以下问题:C++ FileIO::SetFileName方法的具体用法?C++ FileIO::SetFileName怎么用?C++ FileIO::SetFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileIO
的用法示例。
在下文中一共展示了FileIO::SetFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Export
/**
* Saves the board to a file
*
* @param fname
* Name of file to save to
* @return
* True if board is successfully saved
*/
bool Board::Export(const string & fname) const {
FileIO file;
FILEIO_TABLE table;
for (int i = 0; i < 9; ++i) {
FILEIO_ROW row;
for (int j = 0; j < 9; ++j) {
char s[2]; // Because it needs to be added as a char*
s[0] = m_board[j][i] + '0';
s[1] = '\0';
row.push_back(s); // Fill a row
}
table.push_back(row); // Add the row to the table w're going to save
}
file.SetFileName(fname); // Prepare FileIO object for saving.
file.SetTable(table);
return file.Save(); // Save returns true if all is successful.
}
示例2: Import
/**
* Loads a saved board from a file
*
* @param fname
* Name of the file to load
* @return
* True if saved board is found and successfully loaded
*/
bool Board::Import(const string & fname) {
FileIO file;
file.SetFileName(fname);
file.Open();
FILEIO_TABLE table = file.GetTable();
if (table.size() == 9) {
FILEIO_TABLE::iterator tableIt = table.begin();
FILEIO_ROW::iterator rowIt = tableIt->begin();
for (int i = 0; i < 9; ++i) {
for (int j = 0; j < 9; ++j) { // Read a row from the table
m_board[j][i] = atoi(rowIt->c_str());
rowIt++;
}
tableIt++;
rowIt = tableIt->begin();
}
return true;
}
else
return false;
}