| faieq92 (150) | |
| Yes but the file currently has nothing in it as all my efforts to output have failed so I can get any information if I haven't saved anything there? | |
|
|
|
| faieq92 (150) | |||
Yes but the file currently has nothing in it as all my efforts to output have failed so I can get any information if I haven't saved anything there?
shouldn't that work? | |||
|
Last edited on
|
|||
| fun2code (1227) | |
|
Yes it should. Your code (unchanged) results in a file name test.txt being created in my main project folder containing the string entered via the console on my computer. I don't know why it isn't working for you. Are you looking for the file in the right place? Where it is created may depend on what IDE you're using, so check various folders in your project folder. | |
|
|
|
| faieq92 (150) | |
|
I cant run the code. It gives me the error on the file << f; no operater matches these operands? | |
|
|
|
| fun2code (1227) | |
There is no line like this:file << f; in the code above. Did you mis-name something?
| |
|
|
|
| faieq92 (150) | |||
im talking about line 4? | |||
|
Last edited on
|
|||
| faieq92 (150) | |
| ok it has randomly worked now . I have no idea why. C++ will always be confusing me xD . Also do you not sleep :D | |
|
|
|
| fun2code (1227) | |
|
I can't tell from just that. That code works fine for me. Can you post the actual error message? The details can be important. A bit more of your code may help too, for judging context. | |
|
Last edited on
|
|
| faieq92 (150) | |||
This is overwriting what was in the text file before? | |||
|
Last edited on
|
|||
| fun2code (1227) | ||||
|
Not really. The data should get written to the file OK, but it would be all run together. Example:
Might produce
Later, this would appear as a single string. You will want to insert newlines '\n' between elements. eg: DataSave << member.Age << '\n';Inserting a blank space instead would also separate the values enough so they could be read later. | ||||
|
|
||||
| faieq92 (150) | |
|
Yes I actually did that before you told me ( I think im getting slightly better) the new lines that is It gets written to the file. However after I close it and build and run the program again it gets overwritten. I suppose this is because im not feeding/inputting that info that was saved back into the program? If I did it would stay right? | |
|
Last edited on
|
|
| faieq92 (150) | |
| Also should I be outputting the data type to the file too eg if its the postcode should I put post code before it so when it gets red it saves to the appropriate place? I don't know. | |
|
|
|
| fun2code (1227) | |||
|
Yes, the file will be overwritten each time the program is run. If you rename the file between runs then a new "test.txt" will be created. Also, you could easily modify that code to prompt the user for a filename to create.
| |||
|
|
|||
| fun2code (1227) | ||
Yes. If there is an existing file (created in the last program run), you could open it and read the data for your Details objects directly from it. | ||
|
|
||
| faieq92 (150) | |
|
If I prompted the user for a filename would I be able to prompt user to later load chosen file? | |
|
|
|
| faieq92 (150) | |
|
also john grace 20 johnman@hotmail.com 20 stcatherines lu31ul that's what the file currently looks like. should I somehow be making it so the file stores it with Name:John etc or would I be able read this information fine later without having to do that. | |
|
|
|
| fun2code (1227) | |||
I suppose you could keep a file with the names of all files previously created by this program and then present this list (of filenames) to the user, but this complication should come later.
No. You should place only the data to be read in the file (otherwise you get into complicated data parsing). The data format you showed first should work fine. | |||
|
Last edited on
|
|||
| faieq92 (150) | |
|
ok thanks best get cracking with reading the data now. | |
|
|
|
| fun2code (1227) | |||
|
Great. What it seems you are trying to do is to read data from a file if it already exists, or get the data from the user if no file exists yet, and create a file from that. Something like this should work:
| |||
|
Last edited on
|
|||
| faieq92 (150) | |
| Quick question when its reading how can I get it to read integers as integers instead of string as I am getting it to read it all in a loop? | |
|
Last edited on
|
|