I'm pulling my hair out on this one. It's been a while since I've specified a path for an ofstream. I just want a simple file called "abc.txt" in the C: folder and I want to write "abc" to it. Anyone see anything wrong? Thanks.

#include <fstream>
using namespace std;


int main ()
{
    ofstream outs;
    outs.open ("C:\\abc.txt");
    outs << "abc";
    outs.close ();
    return 0;
}

No error messages?

Which OS?
XP and Vista can be a bit twitchy (for good reason) about writing into the root directory of the boot disk.

Should work as long as you are logged into MS-Windows with administrative privileges. If not, then the os may prevent you from writing into c:\\ root directory. Try writing that file to another directory that you know is writable.

I am using Vista Home from an admin account. No error message, but it occurs to me now that I was running it through Dev C++, so I just had a console blink. I'll try running it through a debugger or running it from a console or keeping the console open. I'm not using Vista at the moment, so I can't try it out. I'll try it out when I can and post pack. Thanks.

Okay, I am at my Vista computer again and I just ran it, again from an Admin account. Only this time it worked perfectly. I have no idea what happened before, but it works now, so...Solved. Thanks guys!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.