爲什麼這樣的表達式不可接受?我想原型名爲子功能:processTheSelectedWord接受一個字符串,並沒有返回void函數需要一個字符串
void processTheSelectedWord (string);
我得到的錯誤是:
1-非法使用類型爲void
2- '字符串'未聲明的標識符
這是代碼,如果您需要查看它
#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;
}
}
}提前
解釋爲什麼不在有人開始詢問之前使用名稱空間可能很有用。 – lpapp
@juanchopanza 我沒有包含字符串庫,但我沒有使用(標準::)我改爲使用命名空間,所以我不能看到問題 –
@A_Mattar然後發佈一些真正的代碼。 – juanchopanza