It would be a good idea to store your structs in an STL container, such as a std::vector, instead of an array. One solution is to read a line at a time of input into a std::string, then extract data from that string and into a Stock struct, then add a copy of that struct onto the end of your container. Look into std::getline() and std::ifstringstream.
The reference section of this website should have all the examples you'll need. If you want to make do without stringstreams, what you should realise is that streams can be used as conditions - they were designed so that using one where a bool is expected will indicate the state of the stream. You should also realise that the >> operator on an input stream returns a reference to the stream. For example, if you tried reading from an ifstream into your struct like so:
1 2 3
while (myfile >> s.stockTag >> s.currentValue >> s.numberOfshares) {
// Loop body
}
The body will only execute if it successfully read into s.numberOfshares (because of the way >> associates). Using that, you should be able to figure out how to read your file without knowing in advance how long it is.
because im not really use vector since my class havent use the vector function yet . and i hope to learn other use thing because @vlad last time u also teach me by using vector.. and i hard to get understand to it... sorry
Then you should use the file format where the first field is the number of records corresponding to one Stock. In this case you can return to your original cide where you read StockSize at first.
In this case for each read record of the file you will have to allocate memory for Stock and for StockNode.
Or you can update you structure Stock the following way
I see that your menu contains a suggestion to sort your Stocks. In this case you can use the selection sort with the single linked list defined in your program.
i done my selection sort and bubble sort , because i done with few some example , at earlier for this question i just hard to get with linked list , but when i read the vector.
Vector is easier for me to seperate the 3 part into different variable .
i read some reference and vector is easier , linked list quite hard for me.
because i/m not really understand how it's flow also ..