I have searched through a lot of questions on this website which are pretty much the same, but nothing works for me. In the first place, let me tell you that I am using Code::Blocks and I am using Ubuntu. This is my code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file("code.out");
string write;
getline(cin, write);
file << write << "\n";
file.close();
}
Tried \n
, tried \r\n
(\r
doesn't seem to do anything for me really). Oh and by the way, if you could also make it work with word-by-word reading that would be great. Thank you very much!
EDIT: Hey guys, I solved it. Thanks for the answers tho! I needed to add a ios::app after code.out!