Hi guys,
Looking at this I know it is straightforward, but that hasn't meant that I have been able to get the solution - so here I am! I am entering serial numbers into a set container which is of type string. I want to be able to enter serial numbers into the set until the user simply presses enter, meaning that "blank" stops input. For the code that I will show you, I have used "X" as the way the user stops input. Here is the code:
ItemizedProductLine::ItemizedProductLine(ProductCode pc, double rrp, double sp, int oh, char* desc): ProductLine(pc, rrp, sp, oh, desc){
string serial = "0";
while(serial.at(0) != 'X')
{
cout << "Please enter serial number:" << endl;
cin >> serial;
serialNumbers.insert(serial);
}
}
As you can see, this does allow the user to stop entering data by pressing "X". However, I can see that this is a horrible way of doing it. Furthermore, it does not achieve my real goal of having the user simply press enter to stop input.
I should add that I am aware that using an array would make it very easy. However, I am limited by the fact that I am entering serial numbers as strings. Furthermore, I now really want to know how you do this using strings! Can anyone shed any light on this problem? Thanks in advance.
Daniel