I've been reading quite a few threads about creating new files if one doesn't exist...but I need it specifically for windows, in the current directory we are in.

I've seen
`

ifstream file;
file.open("TehLeetFile");
if(!file.is_open())
    cout<<"Tehleetness is busted!";
else
    cout<<"it work!!!!11!!!11!one!";

`

That's just checking to see if the file is there.

Later on I will need to read the file...but not yet.

Recommended Answers

All 2 Replies

Is this a question? The code that you have will indeed check if the file exists or not. To write to a file, you'd need a std::ofstream, but that's the only difference.

If you include the Common Language Runtime you can use the System namespace and the IO class, which includes the File class. Here's an example which works in VS2010:

#include "stdafx.h"

using namespace System;
using namespace System::IO;

int main(array<System::String ^> ^args)
{
    if(File::Exists("C:\\1.xml"))
        Console::WriteLine("Yes");
    else
        Console::WriteLine("No");
    String^ Test = Console::ReadLine();
    return 0;
}
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.