こんにちは、クラスの絞首刑執行人プロジェクトに取り組んでいるのですが、問題が発生しました。私がやろうとしているのは、ファイルから単語のリストを取得し、1 つのランダムな単語を char 配列に入れることですが、テキストを文字列配列から char 配列に変換する方法が正確にはわかりません。現在このように見えます
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int main(){
ifstream infile;
string words[25];
string wordss;
char cword[];
int index=0;
infile.open("c:\\words.txt)
while (infile>>words){
words[index]=words;
index=index+1;
}
}
もともとは、cword=words[0] のようにランダムに選択された番号を介して、単語配列の 1 つに対して cword 配列をランダムな単語にするだけでしたが、それはうまくいきませんでした。文字列配列から選択した単語をどのように変換して char 配列に使用するのだろうか?