Write last half of the vector to std::ofstream
问题 I am writing code to write a vector to file. My aim is to write the last half of the vector to file first and then the first half based on offset. The code below gives me segmentation fault. std::vector<uint8_t> buffer_(1000); // the vector is filled with values int offset_ = 300; std::ofstream output_file (file_name.c_str(), std::ofstream::out | std::ofstream::binary); if (output_file.is_open()) { output_file.write(reinterpret_cast<const char*>(&buffer_[offset_]), (buffer_.size() -offset_)