Thread: Output For C++

  1. #1
    esi
    Guest

    Output For C++

    I was wondering if there was a way to make my utput print to a file liek notepad or microsoft word instead of it showing in the dos-prompt window

  2. #2
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    If you mean File I/O
    ie, to be able to output to a text file... There are many tutorials about this, and think there is one on this site...
    If you want to see how does it look like, here is an example:
    Code:
    #include <fstream>     //to use file i/o
    #include <iostream>
    #include <cstdlib>     //To use exit();
    using namespace std;
    
    int main()
    {
         ofstream outFile("output.txt", ios::out);
         if ( !outFile )
         {
              cerr << "Output file cannot be opened";
              exit(1);
         }
         //here is where you output to the file.
         outFile << "This is my first output to a file in C++";
         return 0;
    }
    Just read some tutorials for more detailes, like the modes you can open a file with, and you should also learn i/o in binary mode...
    And if you have any further questions, post them here...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM