.txt ファイルからいくつかの名前を取得して char 配列に追加しようとしていますが、奇妙なことが起こります。コードの入力部分は次のとおりです。
int main()
{
string namelist[30];
int i=0;
string line;
ifstream file("C:\\names.txt");
if (file.is_open())
{
while ( getline (file,line).good () )
{
getline(file,line);
cout << line << endl; // It prints the names normally (it was added for debugging) //
namelist[i] = line;
}
file.close();
}
cout << namelist; // Here is the prob.
コードの最後の行で、リストではなくコンソールにポインターを出力しますが、その理由はわかりません。私はC ++にかなり慣れていないので、失礼にならないでください!
テキストファイルは次のようなものです。
John
Nick
Samatha
Joe
...
どんな助けでも大歓迎です:)