1. #include
  2. #include
  3. #include
  1. std::ios
  2. False
  3. eof() is used to check if the end of file has been reached, fail() is used to check if the most recent input/output operation failed, bad() is used to check if a non-recoverable error has occurred, and good() is used to check if the stream is ready for input/output operations.
  4. No question provided.
  1. ofstream outfile("D:\out.txt");
  2. ifstream infile; infile.open("x.json");
  3. if(!infile.is_open()){ cout<<"x.json does not exist"<<endl; return 0; }
  1. auto size = std::filesystem::file_size("x.json");
  2. std::ofstream outfile("D:\out.txt"); outfile<<std::setprecision(1)<<std::fixed<<std::setw(5)<<std::setfill('')<<size/pow(1024,3)<<endl; outfile<<std::setprecision(2)<<std::fixed<<std::setw(6)<<std::setfill('')<<size/pow(1024,3)<<endl; outfile<<std::setprecision(3)<<std::fixed<<std::setw(7)<<std::setfill('')<<size/pow(1024,3)<<endl; outfile<<std::setprecision(4)<<std::fixed<<std::setw(8)<<std::setfill('')<<size/pow(1024,3)<<endl; outfile<<std::setprecision(5)<<std::fixed<<std::setw(9)<<std::setfill('*')<<size/pow(1024,3)<<endl;
  1. std::vectorstd::string poetry;
  2. std::ifstream infile("x.json"); std::string line; while(std::getline(infile, line)){ poetry.push_back(line); }
  3. std::ofstream outfile("D:\out.txt"); for(auto p: poetry){ outfile<<p<<endl; std::cout<<p<<endl; }
  4. std::ifstream infile("x.json"); char c; std::string line; while(infile.get(c)){ if(c == '\n'){ poetry.push_back(line); line = ""; } else { line += c; } }
  1. std::fstream file("inout.dat", std::ios::binary|std::ios::in|std::ios::out);
  2. int size = std::filesystem::file_size("x.json"); double giga = size/pow(1024,3); file.write(reinterpret_cast<char*>(&size), sizeof(int)); file.write(reinterpret_cast<char*>(&giga), sizeof(double));
  3. int size_read; double giga_read; file.seekg(0); file.read(reinterpret_cast<char*>(&size_read), sizeof(int)); file.read(reinterpret_cast<char*>(&giga_read), sizeof(double)); std::cout<<size_read<<" "<<giga_read<<std::endl;
  4. std::array<std::string, 3> poetry = {"first line", "second line", "third line"}; file.write(reinterpret_cast<char*>(&poetry), sizeof(poetry)); std::array<std::string, 3> poetry_read; file.seekg(-1sizeof(poetry), std::ios::end); file.read(reinterpret_cast<char>(&poetry_read), sizeof(poetry_read));
  1. file.seekp(sizeof(int)); double one = 1.0; file.write(reinterpret_cast<char*>(&one), sizeof(double));
  2. file.seekg(-2sizeof(std::string), std::ios::end); std::array<std::string, 3> poetry_read; file.read(reinterpret_cast<char>(&poetry_read[1]), sizeof(std::string));
1The C++ header files 1 for file input is __________; 2 for file output is ____________; 3 for file input & output is ____________ 2The base class for input andor output stream is _________3True or fa

原文地址: https://www.cveoy.top/t/topic/b9o8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录