Arrays,functions,reading from file

Hey everyone and thanks in advance.

I need help with reading text from a file(Shipping addresses and quantity of items) and i need to write the address to an address file and the #items to a receipt file. Along with the # items, I need the number to be passed to a function where it calculates the sub total and total.
1
2
3
4
5
6
7
8
9
10
11
12
13
ifstream inputFile;
string name;
inputFile.open("DoflingyOrders.txt");
ofstream outputFile;
outputFile.open("Receipt.txt");


while(!inputFile.eof())
{
getline(inputFile, name);
outputFile << name << endl;

}	




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void menu()
{
//Asking for users information to be inputed
cout << "Enter the name of the purchaser: ";
getline(cin, name);
cout << "Enter street address: ";
getline(cin, address);
cout << "Enter city: ";
getline(cin, city);
cout << "Enter state: ";
getline(cin, state);
cout << "Enter zipcode: ";
getline(cin, zipcode);
cout << "Enter the number of doflingies ordered: ";
cin >> order;    
}


if i could just get the item amount to be passed to order i think it would work

how could i grab a certain line from the file and set it to order?


sample of the text file

Leslie Knope
1456 Plymouth Street
Pawnee, IN 47408
356

Ann Perkins
217 Lowell Drive
Pawnee, IN 47408
9

Tom Haveford
689 Lil Sebastian Avenue
Pawnee, IN 47408
1100

Ron Swanson
3657 White Bridge Road
Eagleton, IN 47322
67



EDIT* added the sample text file
Last edited on
Well as your code shows already, you can read from file streams just like the standard in and standard out... are you trying to figure out how to read a number in as an int?
The cout << name is just testing to see if I got the file to read properly.

what I am trying to do is take the name and address's and write them into a Manifest txt file. Also, I need to take the numbers(the quantity of items they want) and pass that value to where it will calculate the sub total/tax/total.

The first part of the code promts the user for all of this information, now our teacher wants us to be able to do all of that PLUS have add a menu option to just read from a file and print to the receipt.txt and manifest.txt


thanks for all the help in advance! if there is a video or text that can explain this don't hesitate to link.
Well file streams are almost exactly the same as input/output from prompt, so I don't see how you would have much difficulty putting everything together from what you already have.

My suggestion is to just start working on it and come back if you have really specific questions. Seems like you have a good start parsing the file so far.
Topic archived. No new replies allowed.