gpt4 book ai didi

c++ - 使用 fstream 输入输出

转载 作者:太空宇宙 更新时间:2023-11-04 16:09:32 27 4
gpt4 key购买 nike

谁能告诉我这段代码有什么问题?我总是打不开。

#include <iostream>
#include <fstream>

using namespace std;

int main(){
fstream fs;
fs.open("fsfile2",ios::in|ios::out|ios::binary);
if(fs.is_open()){
fs.write("wow",sizeof("wow"));
char str[20];
fs.read((char*)str,sizeof(str));
cout<<str<<endl;}
else
cout<<"Not open\n";
return 0;
}

最佳答案

试试这段代码

fs.open("fsfile2", ios::app|ios::in|ios::out|ios::binary);

关于c++ - 使用 fstream 输入输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30219490/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com