File I/O Problem
-
>>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
-
>>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+ " " + L_Name[x] + " " + number[x]; write<
-
>>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
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
-
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
-
ya i tryed putting it in a stuct but it would do the same thing so i just tryed it with it out
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