| | |
problem with classes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 12
Reputation:
Solved Threads: 0
I am working on a project that inputs stock information from files, then outputs the information when the customer is called upon. I am doing pretty good, but am stuck. This is what I have.
The problem (I believe) is that when I read the data in from the files (there is a seperate file for each customer) it puts all of it into the same stockvector, so that when I try to call for a specific customer, it doesn't match up with the stock for that customer. Can I create more than one stockvector, or is that impractical?
Please let me know if you need any more code, like my class functions, but I don't believe they are the problem, although I could be wrong.
C++ Syntax (Toggle Plain Text)
for (int k = 0; k < namevector.size(); k++){ //namevector is a vector of type otherfile.close(); customer(defined as a class) otherfile.clear(); otherfile.open(namevector[k].getname().c_str()); if (!otherfile.is_open()){ cout << "Can't open the customers stock file" << endl; } while(!otherfile.eof()){ otherfile >> symbol >> numshare >> price; stocks.setsymbol(symbol); stocks.setnumshare(numshare); stocks.setprice(price); stockvector.push_back(stocks); //stockvector is vector of type stock which is defined as a class } } cout << "Enter customer name, or exit" << endl; cin >> command; for (int n = 0; n < 3; n++){ if (command == namevector[n].getname()){ cout << "found person" << endl; for(int m = 0; m < 3; m++){ cout << namevector[n].getstock(m).getnumshare()<< namevector[n].getstock(m).getsymbol()<< namevector[n].getstock(m).getprice() << namevector[n].getstock(m).getnumshare() * namevector[n].getstock(m).getprice() << endl; }
The problem (I believe) is that when I read the data in from the files (there is a seperate file for each customer) it puts all of it into the same stockvector, so that when I try to call for a specific customer, it doesn't match up with the stock for that customer. Can I create more than one stockvector, or is that impractical?
Please let me know if you need any more code, like my class functions, but I don't believe they are the problem, although I could be wrong.
C++ Syntax (Toggle Plain Text)
otherfile >> symbol >> numshare >> price;
![]() |
Similar Threads
- c-string (C++)
- Python GUI Problem (Python)
- compiling using g++ results to undefined reference (C++)
- a project- visual c++ (C++)
- tomcat jsp problem (JSP)
- Need help in figuring logic for a parser (Java)
- Passing arrays of objects to functions (C++)
- Can't setEnable a button on my Frame (Java)
- Help with Classes (C++)
Other Threads in the C++ Forum
- Previous Thread: Please help me in my Calculation
- Next Thread: help with loops
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






