在c++中,可以使用以下方式定义一个包含多个字符串的数组: #include <iOStream> #include &
#include <iOStream>
#include <string>
int main() {
// 定义一个包含3个字符串的数组
std::string strings[3];
// 初始化数组元素
strings[0] = "Hello";
strings[1] = "World";
strings[2] = "C++";
// 打印数组元素
for (int i = 0; i < 3; i++) {
std::cout << "String " << i << ": " << strings[i] << std::endl;
}
return 0;
}
在上面的示例中,我们定义了一个包含3个字符串的数组strings
,并分别对数组元素进行了初始化。通过循环遍历数组,我们可以打印出每个字符串元素的值。
--结束END--
本文标题: c++中string数组怎么定义
本文链接: https://www.lsjlt.com/news/590466.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0