c 14 vs 11 – sizeof返回不同的值?
发布时间:2020-12-16 06:46:20 所属栏目:百科 来源:网络整理
导读:对于同样的程序,c 11返回2 1 2,但是对于c 14,返回2 1 1给我.我很迷惑.. #include iostream#include stringusing namespace std;int main(){ char a[2]; cout sizeof(a) endl; std::string b("a"); cout b.size() endl; char c[b.size() + 1]; cout sizeof(c)
对于同样的程序,c 11返回2 1 2,但是对于c 14,返回2 1 1给我.我很迷惑..
#include <iostream> #include <string> using namespace std; int main() { char a[2]; cout << sizeof(a) << endl; std::string b("a"); cout << b.size() << endl; char c[b.size() + 1]; cout << sizeof(c) << endl; return 0; } 解决方法
char c [b.size()1];标准C中不允许任何版本.
如果您发现编译器接受了它,那么它是编译器扩展,因此您应该查阅您使用的编译器的文档. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |