我正在尝试实现一个隐藏单词查找游戏,它从文本文件中读取拼图,然后尝试找出隐藏单词的位置。但是,当我尝试进行 top top bottom 搜索时,屏幕上什么也没有出现,即使我编写了一个独立于该方法的简单 cout 命令也是如此。这是代码:(顺便说一句,输出没什么)
bool WordPuzzle::searchTopToBottom(string word){
cout << "asdasda";
string fullWord = "";
int i = 0;
int j = 0;
int index = 0;
int count;
bool a = false;
while (i < numOfColumn){
while (j < numOfRow){
if (word[index] == puzzle[i][j]){
i++;
index++;
count++;
fullWord += word[index];
if (count == word.size()){
a = true;
break;
}
}
else
j++;
}
}
if (a){
cout << fullWord;
return true;
}
else{
cout << "not found";
return false;
}
}
int main (){
cout << "qweqw";
WordPuzzle w ("puzzle.txt");
cout << "qweqw";
w.searchTopToBottom("DEMIR");
return 0;
}
最佳答案
您应该添加 endl
在你的 cout
末尾, 像那样 :
cout << variable << endl;
标准输出是缓冲的,它会等到你写了一个回车符才显示该行。 endl
添加此回车。
关于C++ cout 不适用于该方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19357471/