programming question | |||||||||
|
DrunknMonkey
Member Posts: 153(0.18%) Threads: 23(0.26%) Private Posts: 13 Characters: DrunknMonkey(1) (retired) Drunknfairy(62) (retired) Lynndoria(60) (retired) |
I have a program which reads in 3 file names given by the user and then uses the data on the files to do parallel array sorting.
there is an option for the user to save the organized data to a file that they choose. But when I run the program and try to save out it does not let me enter the name of the file. here is the part of the code dealing with the file saving char sname[50]; else if(choice == 3) { cout << "Enter name of output file: "; cin.getline(sname, 50); fout.open(sname); for(int i = 0; i < nUnits; i++) fout << nameArray[i] << "\t" << popArray[i] << "\t" << areaArray[i] << endl; cout << "Wrote data to file \"" << sname << "\"\n" << endl; fout.close(); } I think that problem has something to do with the returns from when the user types in the other file names not being used up and just sitting there until now...but I'm not sure. If anybody can see what my problem may be, I'd really appreciate it.
|
|||||||||
DrunknMonkey
Member Posts: 153(0.18%) Threads: 23(0.26%) Private Posts: 13 Characters: DrunknMonkey(1) (retired) Drunknfairy(62) (retired) Lynndoria(60) (retired) |
I guess it would help if i said that i initialized istream fin; ostream fout; (but you probably figured that out) all i see are the cout statements and get no chance to input, so im guessing it is just going right into the fout.open line.
what library is cin.flush() found in? I currently have cstring library, iostream, and fstream. and using namespace std; if you need more code to understand or want me to explain something just let me know. and thanks for the help.
|
|||||||||
DrunknMonkey
Member Posts: 153(0.18%) Threads: 23(0.26%) Private Posts: 13 Characters: DrunknMonkey(1) (retired) Drunknfairy(62) (retired) Lynndoria(60) (retired) |
well, with Adam's help I got it working. we ended up using cin.sync().
Thanks for the help jesse
|
|