<fstream> arghghghhhhhhhh

This is a discussion on <fstream> arghghghhhhhhhh within the C++ Programming forums, part of the General Programming Boards category; So here's the problem: When using <fstream> you can do: Code: #include <fstream> using namespace std; void main() { char ...

  1. #1
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377

    <fstream> arghghghhhhhhhh

    So here's the problem:
    When using <fstream> you can do:
    Code:
    #include <fstream>
    using namespace std;
    
    void main()
    {
     char buffer[200];
    
     ifstream fin;
     fin.open("blbalba.txt");
     fin>>buffer;
    }
    And this load up a word in a buffer[], So how can i load up the whole line???
    I need the whole line, Arhghghhhhh!!!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Use getline.

  3. #3
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    allright!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    Code:
     
    read_filevariable.getline(buffervariable,100);

  5. #5
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    There is a wierd character in my text file that makes my getline split, it looks like [] here's a report:

    string ( this is a line ) :
    Code:
    @"Ach! Hans, Run!"@;@UNH@;;@Gld@;@{2}{R}{R}{G}{G}@;@Enchantment@;@@;@Quinton Hoover@;@116@;@R@;@0000@;@At the beginning of your upkeep, you may say "Ach! Hans, run! It's the . . ." and name a creature card. If you do, search your library for the named card, put it into play, then shuffle your library. That creature has haste. Remove it from the game at end of turn.@;
    loads ok

    but
    Code:
    @1996 World Champion@;@PR@;;@Gld@;@{W}{U}{B}{R}{G}@;@Legendary Creature@;@*/*@;@Christopher Rush@;;@R@;@0011@;@Cannot be the targets of spells or effects.
    World Champion has power and toughness equal to the life totals of target opponent.
    {0}: Discard your hand to search your library for 1996 World Champion and reveal it to all players. Shuffle your library and put 1996 World Champion on top of it. Use this ability only at the beginning of your upkeep, and only if 1996 World Champion is in your library.@;@It takes great sacrifice to make it to the top.@
    has a wierd symbol in it ( maybe you can't see it, but it's there ). And the result of getline
    is all the text before symbol. Next getline contains the text after the symbol.
    I hate this symbol!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    If you're trying to read a file that has nonstandard characters, like an mp3, you're gonna have problems. You'll run into carriage returns and other things that will mess with your input. Fstream was meant for text files with ASCII standard characters only.
    Sent from my iPadŽ

  7. #7
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    i'm loading *.txt, And this character is just incredibly wierd. I haven't seen something like this before...
    I tryed to copy that character here, and cursor jumped row below just like i pressed return.
    Strange! // Now i can use CTRL+V instead of VK_RETURN
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  8. #8
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    In notepad This strange character is displayed. While in Vim ( text editor ) the character is spliting lines. Is there a way to ignore this character?
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    >> Fstream was meant for text files with ASCII standard characters only.

    Actually, fstream works with binary as well as text. You can also use it with character sets other than ASCII.

    You may have to read it in as binary if that character is giving you problems. You could also change the delimiter to getline, so that it doesn't stop at the first newline but stops at whatever character you give it.

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    If you opened the file in binary, you could work with it, but that takes a different level of understanding.
    Sent from my iPadŽ

  11. #11
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    So what should my delimiter be, it can't be '\n' 'cause it stops on the character.
    It can't be '.' 'Cause there isn't . on the end of each line...
    There isn't a way out of this.
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  12. #12
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    ...
    ...

    ...

    *clears throat*

    If you opened the file in binary, you could work with it, but that takes a different level of understanding. There is no magical answer that will let what you (and I) know be able to work with nonstandard characters in files.

    ...of you're not happy with that answer, then you should know that most things that you'll have with nonstandard characters will have a filesize or something else in the file that corrupts it when you edit it. Try opening one of your programs in a text editor and deleting a character then run it.
    Last edited by SlyMaelstrom; 11-30-2005 at 04:07 PM.
    Sent from my iPadŽ

  13. #13
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Well how does win Notepad opens this file, and displays it corectly.
    I'm just gonna replace that symbol with another symbol i can read, reccomend me a wierd symbol
    that can be read with <fstream>
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  14. #14
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    use fin.getline(buffer,sizeof(buffer),'\n')
    or whatever delimiter you want to use.

  15. #15
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    What does that have to do with my symbol?
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. use <fstream> and ostream overloading together
    By mosu' in forum C++ Programming
    Replies: 3
    Last Post: 08-16-2006, 01:06 PM
  2. <fstream> again !!!!!
    By ElastoManiac in forum C++ Programming
    Replies: 8
    Last Post: 12-19-2005, 02:45 PM
  3. Debug Help w/ <fstream>
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2005, 04:14 PM
  4. About "fstream" in <fstream.h> and <fstream>
    By L.O.K. in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 05:49 PM
  5. allegro weirdness, <fstream> errors
    By ichijoji in forum Game Programming
    Replies: 2
    Last Post: 02-16-2003, 08:46 PM

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