小编Jay*_*Jay的帖子

无法写入二进制文件

我在C++中有以下代码.

int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
ofstream output("Sample.txt", ios::out | ios::binary);

for(int i = 0; i < 10; i++)
{
  output<<arr[i];
}
Run Code Online (Sandbox Code Playgroud)

现在Sample.txt是这样的:

12345678910
Run Code Online (Sandbox Code Playgroud)

是不是"Sample.txt"应该是二进制文件?当我以二进制模式打开流时,为什么不将所有内容都转换为二进制文件.我该怎么办,因为我需要数组中每个元素的二进制文件,然后将其打印到文件中.

c++

5
推荐指数
1
解决办法
1260
查看次数

标签 统计

c++ ×1