getline not working
-
I'm porting yet another plugin to R20.
In this plugin, I have to parse lines that I read, line by line, from a file.
I was using std functions, namely getline.
But I'm getting "No matching function for call to 'getline'" errors.
Is it a limitation of the new coding environment?
How can I read a stream, line by line and then, parse the line element by element (elements are separated by ', ' (a comma and a space)? -
Hi Rui, thanks for writing us.
With regard to the issue reported, it's likely that, being getline defined in the std:: namespace you're invoking it without explicitly using the namespace being the std namespace not being used by default.
Invoking std::getline() should then fix the issue on your side.
Being said that, I warmly recommend to get rid of using methods outside of Cinema 4D API and instead to have a look at the InputStream Manual and to ParseHelper::ConvertTextToLines static method.
Best, Riccardo
-
I will try it, Riccardo.
The "beauty" of getline is that I can parse value by value, and the line will get shorter automatically, as I read values from it.
Since I use it to parse OBJ and FBX files, changing methods would require me to recode everything. But, sometimes, we just have to bite the bullet and re-write stuff, I know -
I still get the "No matching function for call to 'getlin'" error, for example in this code, even after replacing getline with std::getline:
void polypaint::read_line_indexes(string line, BaseContainer &bc)
{
std::stringstream ss(line);
std::string field;
Int32 index;while (std::getline(ss, field, ', ')) { index = atoi(field.c_str()); bc.SetInt32(store_index_count, index); store_index_count++; }
}
-
Hi rui_mac,
std::getline() in its signature accepts std::basic_istream and not std::stringstream and this is the reason why you're provided back with such an error.
Riccardo
-
It is so weird that it worked in versions pre R20.
Well, I will have to find a new solution, then.