I need my code to read an example of "string:double" but reading through my code it'll give me the string but it also says it cannot be found. i can't figure out why it won't read the error on the left and right side i need to to detect wether or not the string is to the left of the : and the double to the right
class MenuItem
{
private:
string name;
double price;
public:
/// Constructor - initialize the object from a given name and price
MenuItem(string itemName, double itemPrice);
/// Constructor - initialize the object given a single text line
/// using the syntax "itemname:price"
MenuItem(string specification);
/// Print the name and price of this menu entry
void Print();
string filename;
cout << "What is the filename? ";
getline(cin, filename);
/// Create the filestream object
ifstream fin;
/// Attempt to open a file
fin.open(filename.c_str());
/// Test for failure
if (fin.fail())
{
throw string(filename + " could not be opened.");
}
/// Read one line at a time
string line;
do
{
getline(fin, line);
if (line != "")
{
MenuItem nextMenuItem(line);
result.push_back(nextMenuItem);
}
}
while (fin.eof() == false);
/// Close the file
fin.close();
return result;
}
bool InterpretableAsDouble(string s)
{
for (int i = c-'1'; i < s.length(); i++)
{
if (!(s[i] >= 1 && s[i] <= 9))
return false;
}
return true;
}
1st. Use code tags please.
2nd. Your code is very hard to read without any formatting at all. You really need to work on your formatting...
3rd. On my compiler (Code::blocks) I couldn't even get this thing to compile until I added stdlib.
4th. around line 193, instead of
for (int i = c-'1'; i < s.length(); i++)
for (int unsigned i = c-'1'; i < s.length(); i++)
Now it compiles, no warnings, no errors... without the accompanying text file, I can't test it further.