Hi,

I want to read/write data from a file and I don't know how (I'm using Visual studio c++). More exactly, if I have the following code:

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	ofstream newfile;
	newfile.open("exemplu.txt");
	myfile<<"I want to write this in a file\n";
	newfile.close();
	return 0;

}

it compiles and it runs without errors but...where should I write the address of the file where I want to write te sentence "I want to write this in a file"

Thank you and...Happy Christmas! :)

Edited 6 Years Ago by Nick Evan: Added code-tags

You can write files anywhere you want to on your computer as long as your login account has permissions to do that. For example newfile.open("c:\\dvlp\\test\\exemplu.txt");

Thank you for the quick answer! It works :) I had already tried to put the address right there but instead of double backslash I was typin a simple backslash.
Have a nice day!

The first backslash is an escape character, just like when you type \n you are escaping the character n and qualifying that it's a newline. So say you had for example mydir\name in your directory string (or any string for that matter) you then have to escape the \ character to tell it you just want the backslash.

This question has already been answered. Start a new discussion instead.