When using fscanf
to read a string and store it into to a string variable, fscanf
expects a char*
as the parameter following the format string, .i.e., this is how it should be (as far as I know):
char str[<appropriate length here>];
std::fscanf(filepointer,"%s\n",str);
If I have std::string str
instead of char str[]
i get a -Wformat
warning (obviously), and the program crashes with a Segnetation fault
(i dont' know why, yet, but i'm not surprised). Aside from fixing the segfault i'd also do this properly, i.e., without receiving -Wformat
warnings.
Is there a way to do the char*
to std::string
conversion "inline", i.e., inside the parameter list of fscanf
or would I have to create a temporary char*
variable to store the data and convert it to a std::string
afterwards (as described, e.g., here, and I don't see a way to apply this method to my case).