I am using Visual Studio 2017 to practice C++, I have had some experience of C++ on TurboC++. Trying to create a program that reads and writes from file, I am having trouble when I use the "ios::Ate" while opening the file.
file.open("text.txt", ios::ate);
My code is as follows.
#include "pch.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file;
file.open("text.txt", ios::ate);
char a;
while(1){
cin.get(a);
if (a != '0')
file << a;
else break;
}
file.close();
}
When I run this program, is runs without errors but when I open the file it is empty.
I have tried using ios::out and it works fine but I do not want to truncate the file every time I want to write into it.