要给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[0] << endl; // 输出:Hello
cout << arr[1] << endl; // 输出:World
cout << arr[2] << endl; // 输出:!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言string数组赋值的方法是什么