String reading problem

I have a file with lots of string like the following:
12345678,123
12312837,324
21323543,78

I have to read these into strings and I used list and the data.push_back() function to stored the string into list.

However, I have to check the digits of these string are between 0 and 9. Can anyone tell me how to do it? Thank you.

I have done the following.

bool C_rental::read (string filename)
{
ifstream fin ("file.txt");
string in int pos1,pos2;

fname=filename;

fin.open(fname.c_str());
while(!fin.eof())
{
getline(fin,in);

pos1=in.find(",");
pos2=in.find(",",pos1+1);

S_record temp;

temp.code=in.substr(0,pos+1);
temp.quantity=in.substr(pos1+1,pos2-pos1-1);
data.push_back(temp);
}
fin.close();
return true;
}

1. Use indents
2. Use code-wrapper [code][ /code]
3. Point out where the error happens
1
2
3
4
5
6
7
8
9
#include <cctype>

bool isAllDigits(const std::string& s)
{
	for (unsigned i=0; i<s.length(); ++i)
		if ( !isdigit(s[i]) )
			return false ;
	return true ;
}
Topic archived. No new replies allowed.