使用sscaf_s从obj读取顶点线不起作用



这是我第一次为StackOverflow写一个合适的问题,所以如果我犯了错误,请纠正我!

我正在尝试从obj文件加载v、vn和vt行。在从解决方案中获得下一行之后,此代码处于一个while循环中:

string type ("  ");
glm::vec3 vertex;
sscanf_s(line.c_str(), "%s %f %f %fn",&type, &vertex.x, &vertex.y, &vertex.z);

sscann_s行抛出以下警告:

Warning C6067   _Param_(3) in call to 'sscanf_s' must be the address of a string. Actual type: 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *'.
Warning C6270   Missing float argument to 'sscanf_s': add a float argument corresponding to conversion specifier '5'.
Warning C6273   Non-integer passed as _Param_(4) when an integer is required in call to 'sscanf_s' Actual type: 'float *':  if a pointer value is being passed, %p should be used.

我很困惑,因为向量中的三个浮点值肯定会抛出相同的错误。当我运行代码时,我也会在这一行遇到访问冲突写入位置错误。

请帮帮我!我是c++新手!

不能使用sscann_s读取字符串对象,必须读取字符数组。

char buffer[666];
glm::vec3 vertex;
sscanf_s(line.c_str(), "%s %f %f %fn",buffer, sizeof(buffer), &vertex.x, &vertex.y, &vertex.z);

最新更新