#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Read an check some data from a text file in c++


    Hi

    programming language: c++
    Guys pleas someone help about read an check some data from a text file?!

    i have a text file (player\config.txt) that included multiply-line and in per line i have some data...
    but i need to check the line included with: set r_full "value" so if the value is "1" skip and continue but if the value is "0" return error " pleas do this in full screen"
    and force to close App.

    Thank you
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    First, you start with the basics, of just opening the file and printing the contents.
    Code:
    // extract to string
    #include <iostream>
    #include <fstream>
    #include <string>
    
    main ()
    {
      std::string name;
      std::ifstream fin("player/config.txt");
      while ( std::getline (fin,name) ) {
          std::cout << name << "\n";
      }
    
      return 0;
    }
    Then you read up on what goodies std::string has to offer by way of finding strings, extracting data and so forth.
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    7
    Rep Power
    0
    but its not do what i want i need check the line in file and return some result that i said in first post.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Then show us what you have already written and where your problem lies. Be sure to use code tags.

    Also re-read salem's reply and this time try to understand what he's telling you.
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    Originally Posted by raminr63
    but its not do what i want i need check the line in file and return some result that i said in first post.
    I know exactly what you said in your post (and what you wanted as well).

    I also noticed the "pleas do this" as well, which is a pretty big flag indicating lazyness of your part, and expecting a completed answer on a plate.

    We're NOT your homework factory.

    We're your guide for the journey, not some pack-mule to carry you all the way while you're off down the beach or chasing MOTAS.
    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

IMN logo majestic logo threadwatch logo seochat tools logo