| faieq92 (150) | |
| Urm basically its only letting me input for lastname and not first and same again with postcode . I know it doesn't make sense but its skipping some details | |
|
|
|
| faieq92 (150) | |
| so it skips first name and lets me input in 2nd name | |
|
|
|
| fun2code (1227) | |||
We're working with this code, right?
I see an error. You forgot to read in the age from the user. This would throw off whats being entered for what, which could easily cause cin to fail. Data entry must be correct. | |||
|
|
|||
| faieq92 (150) | |
|
fixed it with this out << "Age(Please Enter an Integer(Number)): "; cin >> Data[i].Age; DataSave << Data[i].Age<<"\t"; still not working its skipping first name | |
|
|
|
| faieq92 (150) | |
|
and its definetly a get line problem it skips email and goes to door number then skips road name and does the postcode | |
|
|
|
| fun2code (1227) | |
|
Yeah, I think you are encountering the nasty problems that occur when you mix cin >> and getline(cin) calls. It has something to do with a newline getting stuck in the stream. My file I/O skills are limited because I don't do it much. You can try stuff like adding this after any line where you use cin >> ( your newly added line and line 21 above). cin.ignore(256,'\n'); which may remove the stray newline (if that's what's causing the problem).Or, try using getline for everything. Someone else may have to help you with this part. | |
|
Last edited on
|
|
| faieq92 (150) | |
| Thanks for all your help. Also do you have any idea why Data[i]!=NULL doesn't work? | |
|
|
|
| fun2code (1227) | ||
You're welcome for the help. Did that cin.ignore(256,'\n'); fix anything?
Data[i] is not a pointer, so that comparison is illegal. EDIT: On second thought, Data[i] is a Details object, so Data[i] != not-a-Details object will always be illegal. | ||
|
Last edited on
|
||
| faieq92 (150) | |
|
and no it didn't I might go back to just using cin without get line so if that comparison to null doesn't work how do I check if array is full if so to skip :S | |
|
|
|
| fun2code (1227) | |||
OK, but that will land you back onto problems with blank spaces in strings.
Not sure what you mean by "array is full". The code above is done when i==size in the for loop. | |||
|
|
|||
| faieq92 (150) | |
| I mean to check if details have already been entered into data[I] | |
|
|
|
| fun2code (1227) | |
|
Just check Data[i] for valid data. Your default constructor for a Details object assigns age = 0, if I recall. I was going to suggest you make that -1 instead. If Data[i].age == -1 then details have not been entered. | |
|
|
|
| faieq92 (150) | |
| yes it is age=0; and I only need to check age right not the others such as name strings? | |
|
|
|
| faieq92 (150) | |
| im about to go crazy now its started to wipe the previous data in the file again... | |
|
|
|
| faieq92 (150) | |||
every time I re run the program it deletes old and puts in new | |||
|
Last edited on
|
|||
| Chervil (1203) | ||
Open the file with a mode of ios::app, in order to append the new data at the end of the existing file. ofstream DataSave("test.txt", ios::out | ios::app);That means the file will grow larger each time. I've lost track of the other parts of the code, if you are reading from the file into your array, then the size of the array may need to be increased. I did mention a vector at one point, and that may be useful, depending on the overall design and what it is you are trying to achieve. I don't know whether this is a student project, where you must adhere to a strict specification, or your own where you can choose the requirements yourself. | ||
|
Last edited on
|
||
| faieq92 (150) | |
|
its a student project we have to use arrays also I don't understand this bit of code ofstream DataSave("test.txt", ios::out | ios::app);
| |
|
|
|
| faieq92 (150) | |||
and this is what I have atm | |||
|
|
|||
| Chervil (1203) | |
|
Thanks for sharing your code. I haven't had time to look in detail, but I think it will be useful to all of us who try to help. Opening a file using different mode flags such as append is described in the tutorial here: http://www.cplusplus.com/doc/tutorial/files/ | |
|
|
|
| faieq92 (150) | |
| Also thanks for all the help so far from everyone in this topic. Don't know where id be without the help. I suppose it would be much more basic than it is now and I would've given up trying to add some features. Still have a long way to go but thanks. :D Really Appreciated. | |
|
|
|