0

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.

3
Contributors
2
Replies
22
Views
4 Years
Discussion Span
Last Post by tinstaafl
0

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.

0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.