Reading a part of a file

This is a discussion on Reading a part of a file within the C++ Programming forums, part of the General Programming Boards category; Lets say I have textfile with: hello="yoyo" how do I get the yoyo in a char[50] variable, without any other ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Reading a part of a file

    Lets say I have textfile with:

    hello="yoyo"

    how do I get the yoyo in a char[50] variable, without any other text???

    Thanks for help!!

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    What hast thou tried thus far?

    Pretend you can only access one character at a time (cin.get()). How might you do it then?
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2
    I tried:

    Code:
    while( true ) {
                                infile >> textRead[t]; // read a character
                                if( textRead[t]!='"' ) // if that character is a "
                                        break; // then stop while loop
                                t++;                       
        }
    
        infile >> textRead; // read the rest of the sentence
        cout << textRead; // print the rest of the sentence

  4. #4
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Code:
    if( textRead[t]!='"' ) // if that character is a "
    Consider this post signed

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. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Reading from file into structs..
    By dankas in forum C Programming
    Replies: 14
    Last Post: 10-16-2002, 11:33 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM

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