I am working on a management system in which the user inputs some integers for different prices of items and gets the output.I need to store them in a file and then show the user the review of his week. How can i read a specific line containing lots of numbers separated by white spaces? After reading how can i store the numbers in variables again to show them to the user?
I am a beginner so any kind of help is appreciated
if you think i should use some other approach then guide me.
What i could come up with was to store all the integers in a string then store the pair of the date and string in the file and by using search algorithm find the date and get the required string. But i can figure out the syntax. IS there any other better and easy approach to do it?
int no_of_hen=0;
int price_per_hen = 0;
int Food_hen = 0;
int Shelter_hen = 0;
int Health_hen = 0;
int offsprings_hen = 0;
int no_of_eggs = 0;
int Egg_rate = 0;
int hens_died = 0;
int total_food = 0;
int total_shelter = 0;
int total_health = 0;
int total_offspring = 0;
int total_sell_output = 0;
int output = 0;
int input = 0;
int profit_loss = 0;
//will get input from user then and generate outputs to be stored in above variables
//i was thinking of converting them to a string and them store the string as daily data
string s1 = to_string(Price_per_hen);
string s2 = to_string(Food_hen); // do this for all variables
string s3 = s1+s1; // // do this for all variables
ofstream File("File.txt", ios :: app);
getline (s3, File);
File >> s3;
/* but when user runs program , inputs and closes the program daily
how am i supposed to get all the data for him to review his week? */
I would approach this a tad differently.
Read this http://www.cplusplus.com/doc/tutorial/structures/ and look at the example program. Do you see how a data structure can help you solve this problem?