因此,根据 cplusplus.com,当您通过以下方式将输出流的格式标志设置为科学记数法时
of.setf(ios::scientific)
您应该在指数中看到 3 位加号和一个符号。但是,我的输出中似乎只有 2 个。有任何想法吗?使用 GCC 4.0.1 在 Mac OS 上编译。
这是我正在使用的实际代码:
of.setf(ios::scientific);
of.precision(6);
for (int i=0;i<dims[0];++i) {
for (int j=0;j<dims[1];++j) {
of << setw(15) << data[i*dims[1]+j];
}
of << endl;
}
Run Code Online (Sandbox Code Playgroud)
和一个示例输出行:
1.015037e+00 1.015037e+00 1.395640e-06 -1.119544e-06 -8.333264e-07
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在做一个将一些Pascal(Delphi)代码转换为C++的项目,并希望编写一个大致相当于Pascal"SetLength"方法的函数.这需要引用动态数组,以及长度并分配内存并返回引用.
在C++中,我正在思考一些类似的东西
void* setlength(void* pp, int array_size, int pointer_size, int target_size, ....) {
void * p;
// Code to allocate memory here via malloc/new
// something like: p = reinterpret_cast<typeid(pp)>(p);
// p=(target_size) malloc(array_size);
return p;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有办法将指针类型传递给这样的函数并成功分配内存(可能通过typeid参数?)?我可以用吗
<reinterpret_cast>
Run Code Online (Sandbox Code Playgroud)
不知何故?在使用方面,最终目标如下:
float*** p;
p=setlength(100,sizeof(float***),sizeof(float**),.....);
class B;
B** cp;
cp=setlength(100,sizeof(B**),sizeof(B*),.....);
Run Code Online (Sandbox Code Playgroud)
任何帮助都是最受欢迎的.我知道我的建议代码是错的,但想传达一般的想法.谢谢.