Allow me to suggest the following.
I don't consider it 'smoother', as cin / cout dialogue is not 'smooth', imho.
But I think this might be closer to what you want.
int main (int, char**)
{
// always initialize your variables
// to value you would not expect from input
int a = -99;
double b = 0.0;
std::string c("");
char comma1 = 'Z';
char comma2 = 'z';
std::string str = "10,1.546,Apple 1";
std::istringstream ss(str);
ss >> a >> comma1 >> b >> comma2;
// the last parameter has the default delimiter in it
(void)getline(ss, c, '
'); // to get past this default delimiter,
// specify a different delimiter
std::cout << std::endl;
std::cout << a << " '" << comma1 << "' " << std::endl;
std::cout << b << " '" << comma2 << "' " << std::endl;
std::cout << c << std::endl;
return 0;
}
Results: (and, of course, you need not do anything with the commas.)
10 ','
1.546 ','
Apple 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…