Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,432 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,911 people online right now. Registration is fast and FREE... Join Now!




adapting if statements

 
Reply to this topicStart new topic

adapting if statements

tootypegs
13 Jan, 2008 - 08:22 AM
Post #1

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
hi i have the following code that makes a directory of a name and path stored in the variable 'OUTPUT_FILE'. However after it is created i want to check if it is created correctly then do other calculations for example "if OUTPUT_FILE is created then do something else."

Does anyone know of syntax to check if a file is created. I tried '.open()' but it didnt do what i thought it mite, unless i coded it wrong

CODE


if (hex_att == 16)
     {
      

    mkdir(OUTPUT_FILE.c_str());
}



thanks
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Adapting If Statements
13 Jan, 2008 - 08:30 AM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,013



Thanked: 18 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
Try using stat to retrieve the files statistics, if you can do this then the file must exist.
int i = stat(file.c_str(),&info);
this returns 0 if the file exists.
User is online!Profile CardPM
+Quote Post

tootypegs
RE: Adapting If Statements
13 Jan, 2008 - 11:36 AM
Post #3

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
thank you for the help!
User is offlineProfile CardPM
+Quote Post

carltech
RE: Adapting If Statements
14 Jan, 2008 - 02:34 PM
Post #4

New D.I.C Head
Group Icon

Joined: 19 Oct, 2007
Posts: 42


Dream Kudos: 25
My Contributions
i believe that
CODE
file.open(!failed)
should be if a file opening didnt fail in iostream

This post has been edited by carltech: 14 Jan, 2008 - 02:37 PM
User is offlineProfile CardPM
+Quote Post

tootypegs
RE: Adapting If Statements
14 Jan, 2008 - 03:53 PM
Post #5

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
i seem to be having a few problems withchecking the directory. When i run my prog it does create the directory so it is definatly doing what i thought it was doing however when i path to the new folder it wont put things in it, (sorry this is kind of an overlap problem of my prev pos). I cnt understand when the folder is creating why it wont let me path an ofstream to it
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 05:03AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month