Thread: read from input file

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    18

    read from input file

    I am confuse understanding the statement " the program must be able to read from input file and write into output file"....can anyone help me to clarify this? Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you were using the keyboard and screen
    Code:
    cin >> var;
    // some stuff
    cout << var;
    To use files, you would do
    Code:
    ifstream fin("input.txt");
    ofstream fout("output.csv");
    fin >> var;
    // some stuff
    fout << var;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    18
    any examples program i can try?

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by imjustnew View Post
    any examples program i can try?
    I'd say all Salem's second example is missing is a main() and some data. Try it. Consult documentation for fstream as appropriate. If what you come up with doesn't work the way you expect, post it here.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    hi

    Is "ifstream" used for reading a file and "ofstream" for writing to the file?

    what is "fin"?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    See this link: C++ file io.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird, cannot read from input file? Makes no sense....
    By matthayzon89 in forum C Programming
    Replies: 7
    Last Post: 11-07-2010, 04:57 PM
  2. Replies: 8
    Last Post: 12-08-2009, 12:55 PM
  3. Beginner Help Read Next Line of Input File
    By SkinnieMinnie in forum C++ Programming
    Replies: 10
    Last Post: 11-25-2007, 01:23 AM
  4. Replies: 16
    Last Post: 01-04-2007, 03:38 PM
  5. How to read in empty values into array from input file
    By wpr101 in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2002, 10:59 PM