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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. File I/O Problem

File I/O Problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorialc++data-structures
5 Posts 3 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.
  • S Offline
    S Offline
    scrname
    wrote on last edited by
    #1

    >>L_Name[x] >>number[x]; x++; } read.close(); //Where the user can enter more name do { cout <<"First Name: "; cin >>F_Name[x]; cout <<"Last Name: "; cin >>L_Name[x]; cout <<"Number: "; cin >>number[x]; x++; cout <<"Would you like to enter another name?(y/n)"; cin >>resp; } while((resp=='y')||(resp=='Y')); y=x; //writes the origianl names then the new name but here is where i get the //set of numbers ofstream write("File.txt"); for(x=0; x

    M C 2 Replies Last reply
    0
    • S scrname

      >>L_Name[x] >>number[x]; x++; } read.close(); //Where the user can enter more name do { cout <<"First Name: "; cin >>F_Name[x]; cout <<"Last Name: "; cin >>L_Name[x]; cout <<"Number: "; cin >>number[x]; x++; cout <<"Would you like to enter another name?(y/n)"; cin >>resp; } while((resp=='y')||(resp=='Y')); y=x; //writes the origianl names then the new name but here is where i get the //set of numbers ofstream write("File.txt"); for(x=0; x

      M Offline
      M Offline
      modeonetwo
      wrote on last edited by
      #2

      + " " + L_Name[x] + " " + number[x]; write<

      1 Reply Last reply
      0
      • S scrname

        >>L_Name[x] >>number[x]; x++; } read.close(); //Where the user can enter more name do { cout <<"First Name: "; cin >>F_Name[x]; cout <<"Last Name: "; cin >>L_Name[x]; cout <<"Number: "; cin >>number[x]; x++; cout <<"Would you like to enter another name?(y/n)"; cin >>resp; } while((resp=='y')||(resp=='Y')); y=x; //writes the origianl names then the new name but here is where i get the //set of numbers ofstream write("File.txt"); for(x=0; x

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        OK, let's have a look. You included iostream.h and fstream.h, you should just include iostream and fstream ( drop the h ). The .h versions are the ones created prior to the standard. I think you'll find that you'll then need to put using std::cin;, etc. for all the parts of iostreams you use. Namespaces are just one benefit of using standard headers. You should also investigate using std::vector to hold your data, and probably put it in a struct. The first so you don't have a limit to how many items can be entered, the second to connect the three pieces of data you collect. I dunno what your main problem is though, I'd try flushing the stream perhaps (cin.flush() from memory), or perhaps using the standard C++ headers will even solve the problem. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        S 1 Reply Last reply
        0
        • C Christian Graus

          OK, let's have a look. You included iostream.h and fstream.h, you should just include iostream and fstream ( drop the h ). The .h versions are the ones created prior to the standard. I think you'll find that you'll then need to put using std::cin;, etc. for all the parts of iostreams you use. Namespaces are just one benefit of using standard headers. You should also investigate using std::vector to hold your data, and probably put it in a struct. The first so you don't have a limit to how many items can be entered, the second to connect the three pieces of data you collect. I dunno what your main problem is though, I'd try flushing the stream perhaps (cin.flush() from memory), or perhaps using the standard C++ headers will even solve the problem. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          S Offline
          S Offline
          scrname
          wrote on last edited by
          #4

          ya i tryed putting it in a stuct but it would do the same thing so i just tryed it with it out

          C 1 Reply Last reply
          0
          • S scrname

            ya i tryed putting it in a stuct but it would do the same thing so i just tryed it with it out

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            The struct won't solve your problem, it merely makes your design better. Add an iostream inserter/extracter and things would be really nice. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

            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