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

标签 c++ string input

串果[200];

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

Example:
My mom has apples;
So , fruits array will contain:
fruits[0] = "My";
fruits[1] = "mom";
..........etc.

我该怎么做?

最佳答案

如果您从标准输入读取:

int i = 0;
for (string word; cin >> word; i++)
    names[i] = word;

如果您从 string 中读取,请改用 istringstream

关于c++ - 如何将文本输入到字符串数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13455957/

相关文章:

c++ - 在 Windows 上的 Netbeans 中设置 Mysql C++ 连接器

vb.net - 如何获得其他2个字符之间的字符?

C++ 返回未知类型

Python:在 Unicode 转义字符串上使用 .format()

Java 到 C/C++,或者至少得到 Java 转换后的代码

c++ - 可变参数宏中的模板推导失败

javascript - 如何在输入类型编号中使用替换 javascript 删除点?

C - Do-while 后跟一个带有 int 案例的 switch。验证不好

c - 如何删除从 C 中的 fgets 输入的额外字符?

C++:使用 “().” 和 “()[].”