how to make a console program open a file

I need to know how to how to make console program open a file
like a sound file.

do you have eny ideas?
Last edited on
Use the <fstream> header file from the C++ standard library.

http://cplusplus.com/doc/tutorial/files/
so the fstream is a fiel open header?
Last edited on
Yes. If you read the documentation link I gave you it will show you how to do it.
ok
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
That's exactly right. However, I suggest between opening the file and writing to it, you use std::ofstream::fail() to check that the file has opened correctly.
Topic archived. No new replies allowed.