int i; int Temp ; int tell; ifstream fille ("C:\input.txt") ; /*it's not important just to read some value and assign it with another value and use it in the loop */ fille >> i ; // here read this value from the file Temp = i ; // assign the value with another for(i=Temp;i<20;){ /* here the user enters his data */ cout<< i; cout << "Enter UserName" ; cin >> Register[i].User_NameDOC ; cout << "Enter Password" ; cin >> Register[i].PasswordDOC ; cout << "Enter Email" ; cin >> Register[i].EmailDOC ; break ; }
-
from here to store the previous user’s data in the file which called “file.txt” and use another file which called “tellp.txt” to save the last value of File_data.tellp(); then make the next register begin from this point (File_data.tellp()) as the normal , at the first i didn’t use seekp() cuz i thought that every time user enters data it will be stored but i found that every time user enters data the new data is replaced with the last data ex: if user[0] enter username , passowrd and email and user[1] enter username , password , email the data of user[1] will replace with data of user[0] so i have used seekp() and tellp() but also i found that the data of user[0] it becomes only spaces in the same line the data of user[1] ex: user[0] = hi Guys and user [1] = hello again the file of data which is file.txt ( hello again) this spaces for user[0]
ofstream File_data ; //declare outputfile to sotre the data of users string outPath = "C:\file.txt" ; // so on.. ifstream tellpp ("C:\tellp.txt") ; /* here to read the last value of File_data.tellp() and put it in File_data.seekp() */ tellpp>> tell ;
// here to read this value and tell = File_data.tellp()
cout << tell ; File_data.open(outPath.c_str()); if(File_data.fail()){ cerr << "it's failed" ; } File_data.seekp(tell) ; /* here to assign tell value to seekp() to make user's data store at the end of the previous user's data but the last user his data becomes spaces */ File_data << Register[i].User_NameDOC << Register[i].PasswordDOC << Register[i].EmailDOC << endl ; cout << File_data.tellp() ; tell = File_data.tellp(); /*** here to assign **tell** to **File_data.tellp()** ***/ ofstream tellp; /*here to declare the file which contains File_data.tellp() (tell) */ string outPaaath = "C:\tellp.txt" ; tellp.open(outPaaath.c_str()); tellp << tell; // here saves tell into **tellp.txt File_data.close() ; /* from here this code just to store the i value which in the for loop to use it again ex: if i= 0 the next register it will be equal (**1**)so on .. */ fstream file; string outPaath = "C:\input.txt" ; file.open(outPaath.c_str(), ios::out|ios::in) ; ++i ; file << i ; file >> i ; file.close(); tellp.close();
note: every thing is okey in the code and value of tellp() changes every time i run the code also (i) value in the for loop changes too but i wonder why users’s data is raplaced with spaces or the new data of new user