Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple File Input

Simple File Input

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestiondesign
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jordan C Atlas
    wrote on last edited by
    #1

    Hello, I'm looking for suggestions on how to design an text input file. I imagine that each line of the file would look something like this: Operation argument1 argument2 argument3 etc. I understand how to do file input if you just want to read one word at a time using the >> operator, but I'm not sure how to "check" what the incoming input is. For example, if a line in the input file started with the operation "CreateNewAccount", how do I (programmatically) check what the string says? If I use std::string for the input the >> operator doesn't seem to like it. If I use char arrays, I can't seem to get two strings to be recognized as equal. Thanks you for suggestions for how to do this, or perhaps for better ways to go about it. If there is any part I need to clarify let me know. -Jordan Atlas

    J 1 Reply Last reply
    0
    • J Jordan C Atlas

      Hello, I'm looking for suggestions on how to design an text input file. I imagine that each line of the file would look something like this: Operation argument1 argument2 argument3 etc. I understand how to do file input if you just want to read one word at a time using the >> operator, but I'm not sure how to "check" what the incoming input is. For example, if a line in the input file started with the operation "CreateNewAccount", how do I (programmatically) check what the string says? If I use std::string for the input the >> operator doesn't seem to like it. If I use char arrays, I can't seem to get two strings to be recognized as equal. Thanks you for suggestions for how to do this, or perhaps for better ways to go about it. If there is any part I need to clarify let me know. -Jordan Atlas

      J Offline
      J Offline
      Jordan C Atlas
      wrote on last edited by
      #2

      To be more specific about the problems I was having: I wanted to try to read the words into string variables so that I could compared them to strings indicating which reaction they correspond to. However, if I try to read the words into std::string variables using something like: inFile >> tempString; then I get a compiler error: error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion) I also tried reading the words into char arrays so that I could comapare the char arrays to the string corresponding to a particular operation. If I do that, however, then the comparison doesn't seem to work. Ie: If I read the word "Account" into a char array called charTemp, the statement (charTemp == "Account") seems to evaluate to false (even tho my intention would be for it to be true). I hope that clarifies the problem rather than making it more complicated! Again, I am open to alternative suggestions. -Jordan Atlas

      PJ ArendsP 1 Reply Last reply
      0
      • J Jordan C Atlas

        To be more specific about the problems I was having: I wanted to try to read the words into string variables so that I could compared them to strings indicating which reaction they correspond to. However, if I try to read the words into std::string variables using something like: inFile >> tempString; then I get a compiler error: error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion) I also tried reading the words into char arrays so that I could comapare the char arrays to the string corresponding to a particular operation. If I do that, however, then the comparison doesn't seem to work. Ie: If I read the word "Account" into a char array called charTemp, the statement (charTemp == "Account") seems to evaluate to false (even tho my intention would be for it to be true). I hope that clarifies the problem rather than making it more complicated! Again, I am open to alternative suggestions. -Jordan Atlas

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        Jordan C. Atlas wrote: inFile >> tempString; then I get a compiler error: error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion)

        #include <string>

        Jordan C. Atlas wrote: the statement (charTemp == "Account") seems to evaluate to false You are comparing two pointers that point to different things so they are obviously not equal. To compare the contents of char arrays you have to use strcmp().


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        J 1 Reply Last reply
        0
        • PJ ArendsP PJ Arends

          Jordan C. Atlas wrote: inFile >> tempString; then I get a compiler error: error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion)

          #include <string>

          Jordan C. Atlas wrote: the statement (charTemp == "Account") seems to evaluate to false You are comparing two pointers that point to different things so they are obviously not equal. To compare the contents of char arrays you have to use strcmp().


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

          J Offline
          J Offline
          Jordan C Atlas
          wrote on last edited by
          #4

          Thank you - your answer makes sense. I will continue writing the input file using strings. -Jordan Atlas-

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups