我想在输出文件中写入整数 b 。我尝试提供a的地址,但它只输出前几个字符,字符后没有数字。
这是我的代码:
#include <cmath>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main(int argc, char *argv[])
{
int rank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPIO_Request request;
MPI_Status status;
MPI_Offset offset = 0;
MPI_File fh;
std::string str1 = "output";
const char *na = str1.c_str();
std::string str2 = "#!TDV112";
const char *version = str2.c_str();
MPI_File_open(MPI_COMM_WORLD, na, MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);
if (rank == 0)
{
MPI_File_seek(fh, offset, MPI_SEEK_SET);
// header !version number
MPI_File_write(fh, version, 8, MPI_CHAR, &status);
// INTEGER 1
int a = 1;
MPI_File_write(fh, &a, 1, MPI_INT, &status);
}
return 0;
}