| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
ifstream/ofstream question
ok, this is the order of the process i want to happen :
1. open file w/ data already present in it (data will be a simple '500') 2. read that data (500) and convert to INT varaible (file_data = int variable) 3. add/subtract that data w/ new data (file_data = file_data +- new_data) 4. save the file w/ the total of old data +- new data 5. close that file w/ the new data 6. in a week, i would do this again, but w/ the updated file_data from the previous week here is my code, plz correct or if you have a better way of coding, please explain ... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- int total1[7]; int add1; ifstream member_total ("total_amt.txt"); // 1 member_total = total1[7]; //2 cout << "Amount in TuffLess's account : '" << total1[7] << "'" << endl; cout << "Amount to 'ADD' to TuffLess's bank account?: "; cin >> add1; member_total = total1[7] + add1; //3 member_total << total1[7]; //4 binary '>>' : no operator defined which takes a right-hand operand of type 'int [7]' (or there is no acceptable conversion) -- HOW DO I FIX THIS ? //member_total.close(); //5 THIS CAUSES THE PROGEE TO CRASH AND DOES NOT SAVE NEW DATA IN .txt FILE -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -when i goto read the '1st step' and cout << member_total; 'or' cout << total1; ... i get a memory addy or a '0' respectivly -i cant get the NEW total to save in the file for the next week -when i go to close the txt file, it crashes id appreiciate any help you could provide, thanx much tuffy |
|
#2
|
|||
|
|||
|
So i guess you are saying that it is correct and it works right?
If it isn't whats the error? |
|
#3
|
|||
|
|||
|
-when i goto read the '1st step' and cout << member_total; 'or' cout << total1; ... i get a memory addy or a '0' respectivly instead of500
-i cant get the NEW total to save in the file for the next week -when i go to close the txt file, it crashes those are the problems and this is one of the errors : binary '>>' : no operator defined which takes a right-hand operand of type 'int [7]' (or there is no acceptable conversion) Quote:
its all above phantom, i just re-posted it for you |
|
#4
|
|||
|
|||
|
It seems like a good problem to be fixed..
I am thinking that use should use "Strings" Code:
member_total << total1[7]; i dont think you need it because you have, Code:
member_total = total1[7]; Code:
//member_total.close(); //5 THIS CAUSES THE PROGEE TO CRASH AND DOES NOT SAVE NEW DATA IN .txt FILE this is caused by Code:
member_total << total1[7]; |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > ifstream/ofstream question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|