Appending a file ios::app

Hi,
This is my first post. Hope someone can help. I am trying to append a txt file I created in wordpad using ios::app. However the file is not appending?

Any advice would be great.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <fstream>

using std::cout;
using std::endl;
using std::string;
using std::ofstream;
using std::ios;

int main()
{
	string info = "\n\n\t\tSpancill Hill";

	ofstream writer ("Lyrics.txt", ios::app);

if(! writer)
{
	cout << "Error opening file: " << endl;
	return -1;
}
writer << info << endl;
writer.close();

return 0;
}
working for me.
What's wrong with The code? It works just fine.
Hey folks,

Thanks for responding. It wasn't working for me. Had to put the full path dir into the code to get it to work.

my initial program to create a file worked but just would not append with this one.

Thanks
Probably your program was being run with a different working directory than you expected. If you're running from an IDE like Visual Studio, it might set the working directory the project directory instead of the directory where the EXE actually is.
Topic archived. No new replies allowed.