Like Tree1Likes
  • 1 Post By Salem

read from input file

This is a discussion on read from input file within the C++ Programming forums, part of the General Programming Boards category; I am confuse understanding the statement " the program must be able to read from input file and write into ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    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;
    MK27 likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    2,804
    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, 03:57 PM
  2. Replies: 8
    Last Post: 12-08-2009, 11:55 AM
  3. Beginner Help Read Next Line of Input File
    By SkinnieMinnie in forum C++ Programming
    Replies: 10
    Last Post: 11-25-2007, 12:23 AM
  4. Replies: 16
    Last Post: 01-04-2007, 02: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, 09:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21