gpt4 book ai didi

c++ - 接受字符串的 void 函数

转载 作者:行者123 更新时间:2023-11-27 23:06:34 25 4
gpt4 key购买 nike

为什么这样的表达是 Not Acceptable ?我正在尝试制作一个名为 processTheSelectedWord 的子函数的原型(prototype),它接受一个字符串并且不返回任何内容

    void processTheSelectedWord (string);

我得到的错误是:

1- illegal use of type void

2- 'string' undeclared identifier

这是代码,如果你需要看一下

    #include <iostream>
#include <iomanip>
#include <vector>
#include <fstream>
#include <string>
#include<time.h>
#include <conio.h>
#include <windows.h>
#include <wincon.h>
void processtheselectedword (string);

using namespace std;

void main()
{
srand(time(NULL));
ifstream key;
key.open("Text.txt");

string temp;
int counter = 0;
vector <string> wordslist;
while (!key.eof())
{
key >> temp;
wordslist.push_back(temp);
counter ++;
}

int randomeWord = rand()% counter;
string word_to_guess = wordslist.at(randomeWord) ;
wordslist.erase(wordslist.begin() + randomeWord);

for (int i = 0; i < word_to_guess.length(); i++)
cout << "__"<< setw(4) ;
cout << endl;
cout << word_to_guess << endl;
key.close();
processtheselectedword(word_to_guess);
system ("pause");

}

//process the selected word
void processtheselectedword(string word_to_guess)
{
int trialsNum; //number of trials allowed based on the difficulty level
string dashes;
for (int i = 0; i < word_to_guess.length(); i++)
dashes.at(i) = '_';

char guessedCharacter;
for (int j = 0; j < trialsNum; j++)
{
guessedCharacter = _getch();
for (int i = 0; i < word_to_guess.length(); i++)
if ( word_to_guess.at(i) == guessedCharacter)
{
dashes.replace(i,"guessedCharacter");
cout << dashes;
}
}

提前致谢

最佳答案

您似乎忘记包含 header <string>并指定声明字符串的命名空间。例如你可以写

#include <string>

void processTheSelectedWord ( std::string );

关于c++ - 接受字符串的 void 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23170727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com