I know that even if this were to have worked, and it didnt, I get a c++ forbids comparison between pointer and integer error, that this would be terribly inefficient. Basically, once I use getline, I do not know how to split up the data on the line into different variable types that are seperated by spaces especially with the description being multiple words and the whole line seperated only by spaces. Thanks a lot for any help.
I have learned about ifstream and ofstream to handle input and output to files. Not sure if there is more to it than that. To be honest I missed some class due to my girlfriend getting into a car accident. She is around 7 months pregnant with our first boy. I am a bit behind the class, but I searched through the lecture notes and have not found anything to help thus far.
We definately have not covered vectors yet. I am not sure what an unsigned variable type is. We have basically covered input output of string, int, float, double, we have covered structs, so I am good there. I am not sure what #include<sstream> does or iterator for that matter. I do appreciate you taking your time and I realize it may not be easy to think backwards so to speak and come up with a dumbed down answer, but I just do not follow exactly what you have submitted. We start learning about classes next week.
Simplified:
Vectors are just like arrays, they occupy a contiguous block of memory and can adjust their size as you add more elements to the end using push_back.
Unsigned variables hold a decimal value just like an integer, but they don't have the bit that allows them to store negative values, only positive ones.
<sstream> is the header file for stringstream. You can read values into a string (istringstream) or read from a string (ostringstream) or both (stringstream). You'll find that there's equivalent classes for standard streams (ostream and istream) which I have overloaded operators for input and output of the struct to cin and cout.
Iterators are used just like an index to an array in a for loop, except are custom tailored for use with a vector and the standard template library.
What you specifically need to solve your problem is right there in the istream operator>>. Put the line into a stream, extract the three numeric values and then get the description with another call to getline.
int main()
{
string line;
ifstream infile;
int num, quant, min;
infile.open("inventorytest.data");
infile >> num >> quant >> min;
getline(infile, line);
while(infile)
{
cout << num << " " << quant << " " << min << " "
<< line << endl;
infile >> num >> quant >> min;
getline(infile, line);
}
cin.get();
cin.get();
return 0;
This worked except line gets an empty space before the string I want, but I want to thank you for your responses because they did help me figure it out. Thanks again.