#include <iostream>
#include <array>
#include <string>
using namespace std;
typedef array<string,3> TString;
int main(){
TString str;
str = {"Hi","Example", "Error"};
cout << str[0] <<endl;
return 0;
}
原来的错误代码,我得到:是否有可能创建一个字符串数组,如果是这样,为什么我得到这个错误:错误:期望的表达式?
pruebastr.cpp:10:8: error: expected expression str = {"Hi","Example", "Error"}; ^1 error generated.
上午我在定义数组的方式不对或不好初始化呢?
尝试'TString str {“Hi”,“Example”,“Error”};'而不是。 –
与'std = C++ 11'标志正常工作。 –
“...或初始化不好”。你的'='行不是*初始化*,而是*赋值*。但是,它应该在C++ 11中编译。 – AnT