小编twi*_*nco的帖子

ASCII数据导入:如何在C++中匹配Fortran的批量读取性能?

设置

您好,我有用于读取ASCII双精度数据的Fortran代码(问题底部的数据文件示例):

program ReadData
    integer :: mx,my,mz
    doubleprecision, allocatable, dimension(:,:,:) :: charge

    ! Open the file 'CHGCAR'
    open(11,file='CHGCAR',status='old')

    ! Get the extent of the 3D system and allocate the 3D array
    read(11,*)mx,my,mz
    allocate(charge(mx,my,mz) )

    ! Bulk read the entire block of ASCII data for the system
    read(11,*) charge
end program ReadData
Run Code Online (Sandbox Code Playgroud)

和"等效的"C++代码:

#include <fstream>
#include <vector>

using std::ifstream;
using std::vector;
using std::ios;

int main(){
    int mx, my, mz;

    // Open the file 'CHGCAR'
    ifstream InFile('CHGCAR', ios::in);

    // Get the extent …
Run Code Online (Sandbox Code Playgroud)

c++ ascii fortran

17
推荐指数
1
解决办法
716
查看次数

标签 统计

ascii ×1

c++ ×1

fortran ×1