Jump to content

Open Files In C++

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
Hi,

I was wondering (as I usually do about these things) what commands open files, web resources etc. in C++. For example anyone familiar with MS-DOS (rare) knows that

start [URL="http://www.codecall.net/"]www.codecall.net[/URL]

opens the web resource www.codecall.net .

Also,

start codecall.txt

opens the file codecall.txt. So what command in C++ does this?

#2
lintwurm

lintwurm

    Learning Programmer

  • Members
  • PipPipPip
  • 77 posts
Depending on your OS...

But as far as I can remember you can import the stdlib.h to do these kinds of things...
then just use system("whatever you want to happen for example start codecall.txt");

That should work if you are running windows... (which I am guessing you are?)

#3
Sysop_fb

Sysop_fb

    Programmer

  • Members
  • PipPipPipPip
  • 160 posts
You can open a file as a stream.

ofstream outfile ("myfile.txt");
outfile << "You're a lame file" << endl;
outfile.close();

ofstream - C++ Reference
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts

Quote

system("whatever you want to happen for example start codecall.txt");
Really bad habit to get into. If you have to use a system() call you're doing something wrong. There's huge overhead, and it's really vulnerable to screwing up. Plus you have little to no control over the command once you've called it. Plus it's not portable, so it won't work on anything but Windows. And even then, it's not guaranteed. Not all versions of DOS support the same things.
sudo rm -rf /