是否可以创建一个字符串数组,如果是的话,为什么我会遇到此错误:错误:预期表达式
Is it possible to create an array of strings, if so, why am I getting this error: error: expected expression?
#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:错误:预期表达式 str = {" hi","示例","错误"}; ^生成1个错误。
我是以错误的方式定义数组或不当初始化吗?
确保您的编译器标准标志(STD)设置为至少C 11
您正在使用什么编译器?
clang 3.9.0 -std = C 11:https://godbolt.org/g/g/31ayx7
gcc6:https://godbolt.org/g/0j52zy
编译和工作正常,输出相同:" HI"
相关文章:
- 我的字符计数代码计算错误.为什么
- C++ 错误 为什么这个矢量不输出?
- 当在函数调用中递增值时,程序正常工作,但是如果我们在单独的行中增加值而不是呼叫函数,则会出现错误.为什么
- 我正在将QPixmap传递给QAbstractButton::setIcon而不是QIcon,但我没有得到错误...为什么?
- 在 ZeroMQ 中绑定订阅者套接字并连接发布者套接字会在代码运行时给出错误.为什么
- 分段错误:为什么这里的数组索引越界了
- Box2D不寻常的错误.为什么 0阻止错误
- c++分段错误:为什么这个程序给出运行时错误(SIGSEGV)
- 链接列表错误 - 为什么头和尾引用指向相同地址
- VC++的一个大错误?为什么初始值设定项列表不对结构进行值初始化
- 分配大量内存会产生错误?为什么
- 得到一个段错误.为什么
- 变量名称与函数名称相同,导致编译器错误.为什么
- 访问在相应类的静态函数中创建的对象的私有成员变量不会导致错误.为什么?
- Qt5:此代码使用msvc2012编译正常,但使用MinGW编译时出现错误..为什么?
- 奇怪的错误-为什么编译器试图调用复制构造函数
- 我在使用 std::map 时收到此错误.为什么
- 我写了这个程序来反转链表中的元素,在编译这个程序后,在reverse()中显示错误.为什么
- Valgrind报告写入错误?为什么?
- 编译器错误 - 为什么我不能在Sublime Text 2中构建C++?