problems with spaces...

This is a discussion on problems with spaces... within the Game Programming forums, part of the General Programming Boards category; At the moment i am making a game that requires reading from file and then outputting that. At the moment ...

  1. #1
    Unregistered
    Guest

    problems with spaces...

    At the moment i am making a game that requires reading from file and then outputting that. At the moment I cannot output anything after the first space in a line. For example:

    char data[50];
    fin>>data;
    cout<<data;


    Here is the file:

    This is the data



    here is what the program displays:

    this



    what can i do to fix this?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try fin.getline()

  3. #3
    Unregistered
    Guest
    Um... Thanx, but could you please tell me what to put IN the fin.getlin()? Becuase i looked it up and i couldnt make heads or tails of it.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Sorry I was not more clear. Here is the prototype for the function:

    istream& getline( char* pch, int nCount, char delim = '\n' );

    So, you might say something like this...

    fin.getline( data, 999, '\n' );

    This says, store the information from file in the field "data" , second parameter is how many characters to read in, and the last parameter is the delimiter which defaults to newline or can be used if you want to stop when a certain character is reached.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 03:59 AM
  2. string input...with white spaces?
    By Pureghetto in forum C Programming
    Replies: 6
    Last Post: 03-10-2003, 01:52 PM
  3. tabs to spaces with dev c++ v.4
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 02:07 PM
  4. Parsing file for spaces (filter)
    By Lynux-Penguin in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2002, 02:58 PM
  5. set spaces in Tab.
    By nilrac in forum C Programming
    Replies: 8
    Last Post: 11-14-2002, 01:58 PM

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