Hi,
I am having trouble writing code that will read the index of a
value located in another file, that the user is searching for. I have an external file that contains part numbers, along with data about each part. What I want to do is to be able to enter a part number, search the file for that part number and return the index (where that part number is in the file) so that later I can read whatever data I want from that line.
My biggest obstacle at the moment is the syntax to be used when I want to read in data from the file to the instream so that I can do something with it.
The commandCode:#include <iostream> // cout, cin, <<, >> #include <fstream> // ifstream #include <string> // string (future) #include <vector> // vector<T> (future) #include <algorithm> // max, min_element() (future) // #include "myVector.h" // read(), mean() (future) #include <cassert> // assert using namespace std; const int CAPACITY = 3; const int DOLLARS = 9999; int number[CAPACITY] = {0}; int price[DOLLARS] = {0}; int key = 0; int main() { ifstream inFile("product.txt"); assert(inFile.is_open()); inFile >> number >> price; cout << "Enter a product number: "; cin >> key; for (int i = 0; i <= CAPACITY; i++) { if (key == number[i]) //find the file index where value of key is stored { return i; } } return -1; cout << "The index is: " << number[i]; // display the index, so that it can be used later. }
generates a "binary >>" error, saying that there is no operator which takes a right hand operand of type int[3].Code:inFile >> number >> price
I believe the compiler has a point, but I don't know what to do to make it happy. Any thoughts or ideas?
I am using MSVS.net 2003
Thanks.



LinkBack URL
About LinkBacks


