我SIGABORT
在运行此代码时得到。我发现我应该使用方括号,但为什么行为是相同的。
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double * dp = new double (5); // what do round brackets mean, and why the behvior
std::ifstream fid("testdata.txt");
fid >> dp[0] >> dp[1] >> dp[2] >> dp[3] >> dp[4];
fid.close();
}
“testdata.txt”的内容是:
4.0 5. 6. 6. 8. 7. 952.
仅当文件中有 5 个或更多双打时才会发生此错误。