i want to write a proggram that keeps tracking of pays and stuff i want to know is there anyway to like tell my program to go line number 10 (i dont know how long his/her name gonna be! like or go to line that says (history: ) or (stats:)??
this is code i'm writing
// Budgettrack.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
class user{
public:
string name,total;
void reduce(int amout){
}
void increase(int amout){
}
} a;
void get_stats() {
cout << "Enter Username: ";
cin.ignore();
cout << endl;
getline(cin,a.name);
cout << "Hi " << a.name << " Please enter your total current budget: ";
cin >> a.total;
cout << "Thanks!!!! \n";
fstream myfile;
myfile.open("information.txt");
myfile << a.name << "\n";
myfile << a.total << "\n";
}
int _tmain(int argc, _TCHAR* argv[])
{
fstream myfile;
myfile.open("information.txt"); // keeps user info
getline (myfile,a.name); // copys the name from file to a.name
cout << "Hellow " << a.name << " ";
getline (myfile,a.total); // same whit budget
int option;
begining: // did this to get back to main menu when i want!!!! any other ideas to do this??? (java dont have goto what if i wanted to write in java?
cout << "Welcome to BudgetTrack! your budget is: " << a.total << endl;
cout << "Press 1 to Enter User Stats(deletes previuse)\n" << "Press 2 for Tracker\n"; // as you see 1 gets user info 2 goes to application!!!!! (u can add stuff like total pays and stuff and budget left)
cin >> option;
switch (option){
case 1:
get_stats();
goto begining;
case 2:
cout << "1.Reduce money\n 2.increase money \n 3.remember to pay\n";
cin >> option;
case 0: return 0;
default:
cout << "Number not valid!!!" << endl; goto begining;
}
return 0;
}
i want to write a proggram that keeps tracking of pays and stuff i want to know is there anyway to like tell my program to go line number 10 (i dont know how long his/her name gonna be! like or go to line that says (history: ) or (stats:)??
I have no idea what to make of this. Can you possibly restate your question (possibly with a simple example)? From what [little] I can gather from the rest of your post, you want to be able to repeat a section of code maybe?
begining: // did this to get back to main menu when i want!!!! any other ideas to do this??? (java dont have goto what if i wanted to write in java?
this app creates a file named history.txt and its like coffee : 100 next line chocolate : 120
i want to make a feature that when u type coffee tell u the cost and date !!!!! and tell u total (-) and total (+) usage!!! and tell u what totally cost u most!!! like i wanna search into file and know the line that that coffee is in!!!! sorry for my bad English!!!! if u cant still understand i will explain tomorrow so sleepy and angry....!!!
i want to search for a line or world in the txt file and set pointer there!!!
Hi, sorry for the late reply *insert some lame excuse*
Please keep in mind that my experience with file handling is limited and primarily in Java, so don't let my thoughts weigh too heavily.
I can think of a couple of approaches (none of which I have tested :0):
1) When the user input is received, sequentially search the file (so start at the beginning and process each line until either there are no more items to be processed or a matching item is found)
2) The other approach would be read in each item from the file and store it in some container (I was initially thinking about some sort of associative container, but this would be an excellent problem to solve using OOP). So you could create a class (I'll refer to the class as MenuItem). MenuItem would have data members for the name of the item, the cost and whatever else you need (would be stored in the file).
Read in each line from the file (one at a time or course) and separate each data entry for that line and store the values in the corresponding MenuItem object that would be put in a vector (or other). You could provide some comparison operators, but without further detail and clarification, I think we can [safely] omit them (at least for now).
I like the second option because 1. You don't have to continuously move around the file (which, of course, is just my uninformed [and ignorant] opinion), 2. it uses OOP (and in a rather appropriate way too I might add) and 3. I believe (and may be wrong in doing so) that the standard library had some functions for searching and such (I have a few tabs open and have found a few that look like they might work, but I think that a class can only be used if it has some comparison mechanism, for example: std::find "uses operator==" [from std::find reference]).
ok!! i will forgot about it:((( i didnt really understand what u mean in 2 and dont know exactly how to change line one by one!!! that was the question i mainly made this thread for first!!!:D