C + + to determine whether the file exists

Source: Internet
Author: User

Judgment file

The code is as follows Copy Code


#include <fstream.h>void main () {
Ofstream f ("C:\test.txt");
Open file Test.txt, for writing, if the file does not exist, create it first

Cases

The code is as follows Copy Code

#include <iostream>
#include <fstream>
using namespace Std;
#define FILENAME "Stat.dat"
int main ()
{
FStream _file;
_file.open (filename,ios::in);
if (!_file)
{
cout<<filename<< "not created";
}
Else
{
cout<<filename<< "already exists";
}
return 0;
}

Cases

Char szdirname[] = "File path";

The code is as follows Copy Code
CreateDirectory (Szdirname, NULL);

That's it, okay?

CreateDirectory
Function:
This function creates a new directory. If the underlying file system supports security in files and directories, the function applies a specified security Descri Ptor to the new directory.
(Create a new folder.) If the basic file system supports a security description on a file or folder, the function will apply the specified security description on the newly created folder.
Prototype:

The code is as follows Copy Code
BOOL CreateDirectory (
LPCTSTR Lppathname,
Lpsecurity_attributes lpsecurityattributes
);

Parameters:
Lppathname: A string that contains the path to the folder that will be created, with a length of not more than MAX_PATH.
lpSecurityAttributes: ignored, set to null
return value:
Returns Non-zero for success and zero for failure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.