gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:04:51 25 4
gpt4 key购买 nike

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

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

string type ("  ");
glm::vec3 vertex;

sscanf_s(line.c_str(), "%s %f %f %f\n",&type, &vertex.x, &vertex.y, &vertex.z);

sscanf_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.

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

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

最佳答案

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

char buffer[666];
glm::vec3 vertex;

sscanf_s(line.c_str(), "%s %f %f %f\n",buffer, sizeof(buffer), &vertex.x, &vertex.y, &vertex.z);

关于c++ - 使用 sscaf_s 从 obj 读取顶点线不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58917799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com