如何将文本输入到字符串数组中?

Joh*_*nie 1 c++ string input

串水果[200];

如何将字符串输入数组?

Example:
My mom has apples;
So , fruits array will contain:
fruits[0] = "My";
fruits[1] = "mom";
..........etc.
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Xia*_*Jia 6

如果您正在阅读标准输入:

int i = 0;
for (string word; cin >> word; i++)
    names[i] = word;
Run Code Online (Sandbox Code Playgroud)

如果您正在阅读string,请istringstream改用.