我在尝试读取包含单词搜索字母的文本文件(如下)时遇到问题。我想将文本文件作为数组读取,然后能够将我的dictionary.txt中的单词与wordsearch_grid.txt匹配。有任何想法吗?
wordsearch_grid:
9
E M M A R G O R P
C L U A U N L L D
O T A O F I L O I
M E U N J G E O K
P W H K G G H P Q
I C O M P U T E R
L L V R Z B A O X
E H O M L E Q G U
T N I R P D C O E
dictionary:
COMPILE
COMPUTER
DEBUGGING
HELLO
KITCHEN
GRAPHICS
LOOP
SPAN
PROGRAMME
WORLD
我到目前为止的代码如下:
#include "WordSearch.h"
#include "fstream"
#include <iostream>
#include <string>
#include "vector"
using namespace std;
vector<string> list;
vector<string> grid;
string line;
string n;
WordSearch::WordSearch(const char * const filename)
{
}
WordSearch::~WordSearch()
{
}
void WordSearch::ReadSimplePuzzle() {
ifstream inFile;
inFile.open("wordsearch_grid.txt");
if (inFile.fail())
{
cerr << "Error Wordsearch Grid File" << endl;
exit(1);
}
else
{
while (getline (inFile, n))
{
cout << n << endl;
}
//grid[4][3];
inFile.close();
//cout << grid << endl;
cout << "\n" << endl;
}
}
void WordSearch::ReadSimpleDictionary()
{
ifstream inFile;
inFile.open("dictionary.txt");
if (inFile.fail())
{
cerr << "Error Dictionary File" << endl;
exit(1);
}
else
{
int count = 0;
while (getline(inFile, line))
{
list.push_back(line);
cout << line << endl;
}
inFile.close();
}
}
void WordSearch::SolvePuzzleSimple()
{
}
到目前为止,它可以读取文件并显示它们,但我希望能够操作网格,以便我可以匹配说“COMPILE”的第一个和最后一个字母以匹配网格中的 2 个字母并输出到输出.txt "在 [1][2] 找到编译