I think a map would be best for you.
If the file has one data item per line, then getline will get the data item on that line, I prefer to use the string version of getline though
string BufferedData;
PHP Code:
//add this at the top of your main
#include <map>
#include <string>
//and this near the beggining of main
//it says create a map, which is alot like an array except it gets bigger and smaller, and instead of looking up an item by a number you can look it up by an item number, or string, or anything you want that has comparison operators
map<int, string> productList;
//the KEY is an integer, which will be the product number, and the data being stored is the name, which will be a string
//now lower down in the loop where you are getting the file read in we will put the data in the map
int tempNum;
string tempName;
while (! inData.eof() ) //I personally prefer inData.good() which is true whever eof is not reached AND there is no error, two birds in one stone and you don't have to use the ! operator
{
inData>>tempNum;//assuming the number is first
getline(inData, tempName);//this gets the name of the product, which can follow the item number on the same line I thin, You won't be needing that char array anymore
//with this you'll be using a dynamic string, meaning you don't have to tell it how many chars, it gets bigger and smaller as needed
//first parameter is the istream your reading from, second parameter is the string you want it stored in
//now we take our data and put it into the map like so
productList[tempNum]=tempName;
}
//now that'll take you through the file and get the numbers and names and store them in the map
cout<<"Enter the item number you want to look up: ";
cint>>tempNum;
cout<<endl;
cout<<productList[tempNum];//this will put out the product name that corresponds with the item number entered
you can also change map<int,string> to map<string,int>
this would mean you would add to the map like so
productList["Name of product"]=5635;
similarly using variables
productList[productName]=itemNumber;
and look up like this
cout<<productList[productNameImLookingFor];
Hope that wasn't to much, as mentioned before you could use a structure for your product,
PHP Code:
//this would go in a header file or at the top of your cpp file above main, along with the #include stuff, just like an int contains 4 bytes of memory that represent a number you can make your own data types that consist of other data types that already exist
struct productDataType
{
int itemNum;
string name;
double price;
}
int main(){
map<int, productDataType> productList;//create the map
productDataType OneSingleProductVariable;//create a product
//the product contains an integer, a string, and a deceimal(double)
OneSingleProductVariable.itemNum=19695;//the . operator accesses the piece of the product
OneSingleProductVariable.name="Marshall Tube Amp";//pretend it's just a string and your assigning that string a value
OneSingleProductVariable.price=1599.95;//and the same with the decimal
//now I store all three variables into the map in one swift action
productList[19695]=OneSingleProductVariable;
//I hard coded the item number in there, in reality it'd be like this
productList[OneSingleProductVariable.itemNum]=OneSingleProductVariable;
//OneSingleProductVariable.itemNum returns the value stored in itemNum which is a part of OneSingleProd..Var
//now to get the product back out you look it up by it's item number
productDataType TemporaryProduct;
TemporaryProduct=productList[19659];
//this stores the product that is looked up by the item number into the temporary product, now you can output the parts like so
cout<<TemporaryProduct.itemNum<<endl;
cout<<TemporaryProduct.name<<endl;
cout<<TemporaryProduct.price<<endl;
Good luck with that, It's late here and I hope I haven't made any serious goof ups, if you had posted your entire program I would have made it so that I could test it and make sure it compiled and ran