Em có 1 file text.txt có nội dung là:
123456789
Làm sao mở và ghi vào trong file để nó không mất dữ liệu trong file, và mình có ghi tiếp sau cái chuỗi kí tự kia được vậy mấy anh chị? VD sau khi ghi thêm abc:
123456789abc
#include<iostream>
#include<fstream>
int main(){
std::fstream file;
file.open("text.txt", std::ios::in);
if (file.fail()) {
std::cout << "\n File khong ton tai.";
system("pause");
return -1;
}
file.close();
file.open("text.txt",std::ios::out);
file.seekp(std::ios::end);
file<<"abc";
file.close();
return 0;
}
Em viết đoạn code như trên khi mở file ra chỉ hiện " abc"