开发平台(Platform): (Ex: Win10, Linux, ...)
FreeBSD 11.2
CentOS 7.5.1804
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
VS code
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
问题(Question):
我想要new一个int阵列用来当作pipe使用,
举例来说假设指令是ls | cat | cat,
那我会有一个int pipenum=2,再执行
int *pfd = new int[2*pipenum],然后分别执行
pipe(pfd) pipe(pfd+2),再来使用这两个pipe传资料
但是有时候在new array的时候会有下面这个错误讯息
然后程式就被terminate了
请问是我new array的方式有什么问题吗?
还是跟OS有关呢?
感谢
预期的正确结果(Expected Output):
new 一个int array
错误结果(Wrong Output):
terminate called after throwing an instance of 'std::bad_array_new_length'
what(): std::bad_array_new_length
Abort trap (core dumped)
可能的原因我google了一下有:
1. If the array size is less than zero.
2. If the array size is greater than an implementation-defined limit.
3.If the number of elements in the initializer list exceeds the
number of elements to initialize.
1是不可能的,所以我猜是2,那这样算是OS的问题吗?
程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档)
vector <string> commands=SplitString(line," | ");
pipenum=commands.size()-1;
cout<<"here"<<endl;
int *pfd = new int [2*pipenum];
cout<<"there"<<endl;
line是我的input command
结果只有印出here,所以我想应该是这行的问题