阅读量:141
要给string数组赋值,可以使用以下方法之一:
- 使用索引赋值:
string arr[3];
arr[0] = "Hello";
arr[1] = "World";
arr[2] = "!";
- 使用循环赋值:
string arr[3] = {"Hello", "World", "!"};
要从string数组中取值,也可以使用索引操作符[]来获取指定位置的值。示例:
string arr[3] = {"Hello", "World", "!"};
cout << arr class="hljs-number">0] << endl class="hljs-comment">// 输出:Hello
cout << arr class="hljs-number">1] << endl class="hljs-comment">// 输出:World
cout << arr class="hljs-number">2] << endl class="hljs-comment">// 输出:!