Inputting Strings from a file

This is a discussion on Inputting Strings from a file within the C++ Programming forums, part of the General Programming Boards category; This is my program: #include <iostream.h> #include <fstream.h> int main () { ifstream fin ("whatever.txt"); char x[6]; fin >> x; ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    Inputting Strings from a file

    This is my program:

    #include <iostream.h>
    #include <fstream.h>

    int main ()
    {
    ifstream fin ("whatever.txt");
    char x[6];
    fin >> x;
    cout << x;
    return 0;
    }

    All that this does is get one character from the file, but I want to read in an entire string, of length 1 to 6. How?

    Thanks for any help

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    use a loop.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    5
    My problem is that there are two different strings of variable length. Is there an end of line function?

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    carriage return acts as an end of line

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  4. Writing strings to file
    By Ichmael™ in forum C++ Programming
    Replies: 6
    Last Post: 07-12-2005, 01:37 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

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