I need to read some values from a text document

I first did a program ("Program 1") to enter some values, and then write them in a text file:

Now I need a new program, or to continue ("Program 1"), but now I need to read the values, so I can do some calculations, and I dont know how to read them.

The text document where I have to read the values from, should be something like this:
------------------
5;2 // 5 is for the number of products, 2 is the number of families

13;14;2;4;2; // these are the proces times of each product
2;2;2;1;1; // these are the families of each product
---------------------
"Program 1"

#include <iostream.h>
#include <fstream>
#include <stdlib.h>
#include <fstream>
#define MAX_PRODUCTS 200
#define MAX_FAMILIES 20
#define MAX_TPROCES 200
int main()
{
int numProducts, numFamilies;
int cont1, cont2, cont3, cont4, cont5;
cont1 = cont2 = cont3 = cont4 = cont5 =0;
inici1:
cout<<("enter the number of products, between 2 and 200")<<endl;
cin>>numProducts;
cout<<endl;

if ((numProducts > MAX_PRODUCTSS) || (numProducts <= 0))
{
cout<<("the number of products entered is incorrect")<<endl<<endl;
system("pause");
system("cls");
goto inici1;
}
else
{
inici2:
cout<<("enter the number of families, between 1 and 20")<<endl;
cin>>numFamilies;
cout<<endl;
cout<<endl;

if ((numFamilies > MAX_FAMILIES) || (numFamilies > numProducts) || (numFamilies <=0)) //
{
cout<<("the number of families entered is incorrect")<<endl<<endl;
system("pause");
system("cls");
cout<<("enter the number of products, between 2 and 200")<<endl;
cout<<numProducts<<endl<<endl;
goto inici2; }
else
{
cout<<endl;
system("pause");
system("cls");
cout<<("enter the time of proces for the ")<<numProducts<<(" products")<<endl<<endl;
cout<<("Remeber that the maximum proces time for a product is ")<<MAX_TPROCES<<endl<<endl;

typedef int carproducts [numProducts];
carproducts tproces, familiap;
while (numProducts - 1 >= cont1)
{
inici3:
cout<<("enter the proces time of the product number " )<<(cont1+1)<<(" : ");
cin>>tproces[cont1];
if ((tproces[cont1] <=0) || (tproces[cont1]>MAX_TPROCES))
{
system("cls");
cout<<("enter the proces time of the ")<<(numProducts - cont1)<<(" products remaining")<<endl<<endl;
cout<<("remember that the maximum proces time for a product is ")<<MAX_TPROCES<<endl<<endl;
goto inici3;
}
else
cont1=cont1 + 1;
}
cout<<endl;
system("pause");
system("cls");
cout<<("enter the families for the ")<<numProducts<<(" products")<<endl<<endl;
cout<<("remember there are just")<<numFamilies<<(" families")<<endl<<endl;
while (numProductss - 1 >= cont2)
{
inici4:
cout<<("enter the family for the product number " )<<(cont2+1)<<(" : ");
cin>>familiap[cont2];
if ((familiap[cont2] <=0) || (familiap[cont2]>numFamilies))
{
system("cls");
cout<<("enter the families of the ")<<(numProducts - cont2)<<(" products remaining")<<endl<<endl;
cout<<("remember there are just ")<<numFamilies<<(" families")<<endl<<endl;
goto inici4;
}

cont2 = cont2 + 1;
}
cout<<endl<<endl;
system("pause");
system("cls");
cout<<("data has been entered correctly")<<endl<<endl;
system("pause");

inici5:
using namespace std;

ofstream fitxertext;
fitxertext.open("Problema.txt");
fitxertext<<numProducts<<(";")<<numFamilies<<endl<<endl;
while (numProducts - 1 >=cont3)
{
fitxertext<<tproces[cont3]<<(";");
cont3=cont3 + 1;
}
fitxertext<<endl;
while (numProducts - 1 >=cont4)
{
fitxertext<<familiap[cont4]<<(";");
cont4=cont4 + 1;
}
fitxertext.close();
system("pause");
return 0;
}
}
}

* I translated the program a bit, so you may find some erros

Thank you very much
You may want to use the tags to make that neater, but to read from a file (Just a note, the comments are extremely dumbed down because I wrote this snippet as part of a tutorial for a beginning C++ class):
1
2
3
4
5
ifstream fileIn ("<FILE NAME>"); //Make a new stream that gets INPUT from a file.
string str;
int number;
getline(fileIn, str); //Put whatever text is in the first line of the fileIn stream into the string called str
number = stoi(str); //"stoi" means "string to integer" 


Assuming that the first line of the input file is a number, that will take the string of text, convert it to an int, and put it into "number." If you want to read in more lines, just call getline again and it will begin reading from where the last function call left off.
Topic archived. No new replies allowed.