Programming question

Edward Glowacki glowack2@msu.edu
Fri, 19 Jan 2001 15:33:56 -0500 (EST)


On Fri, 19 Jan 2001, Don Chorman wrote:
> I am writing a program in C++, and I need it to write to
> a new file. I'm know how to do this part, but I want to 
> avoid overwriting files, or atleast warn the user that a 
> particular file exists. Can I code this in C++?
> Can I run shell scripts within a C++ program?
> I ask because I see scripts doing a similar checks, and
> I could use that code as an example to go by.
> Thanks,
> Don 

The quick and relatively useless answer is: Yes, and Yes.

There are probably a dozen different ways to check to see if a file
exists.  "stat()" is one such C call you can use, there might be 
better ones for C, and for C++ there may be some others, but at
least its a place to start.

As for running shell scripts from C++, you should be able to do that,
though I'm not sure of the exact calls you would need to make right
off the top of my head, but if you just want to do it to check the
existance of a file, don't. ;)  After all, scripts run through
an interpreter that is probably written in C that will just make
the same call you would make, but with a *lot* more overhead. =)

-- 
Edward Glowacki			glowack2@msu.edu
Technical Support Services		
Michigan State University