嗨基本上我真的試圖讓一個字猜謎遊戲,一切工作正常,但我只是不能連接的信件,我什麼都試過改變類型,使用srtcat,追加或+,在代碼波紋管的問題評論說。我該如何解決它?串接字母問題
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string.h>
using namespace std;
int main()
{
time_t t;
srand((unsigned) time(&t));
int randNum = (rand() % 4);
string animals[5] = { "dog",
"fox",
"wolf",
"cat",
"mouse" };
char letters_input;
char placeholder = '_';
bool wordnotfound = true;
char output;
int cnt = 0;
cin >> letters_input;
while (wordnotfound)
{
string word = animals[4];
for(int i=0;i<word.length();i++)
{
if (letters_input == word[i])
{
//strcat(output,word[i]);
//output += word[i];
}
else
{
//strcat(output,placeholder);
//output += placeholder;
cnt++;
}
}
cout << output << endl;
if(cnt == 0)
{
wordnotfound = false;
}
else
{
cin >> letters_input;
cout << output << endl;
}
}
system("pause");
return 0;
}
'output'是'char'。一個'char'永遠只能容納一個角色的價值的數據。您因此使用了錯誤的類型。 – Jon