我试图让"CMtoaPlugin::listArnoldNodes()“返回一个字符串数组
std::vector<std::string> ArnoldNodes = CMtoaPlugin::listArnoldNodes();
std::vector<std::string>::iterator it;
for ( it=ArnoldNodes.begin() ; it < ArnoldNodes.end(); it++ )
{
printf("initialize shader %s\n", *it);
}但这是我得到的,2个条目,这是正确的,但条目的内容不是
初始化阿诺德着色器†.../
初始化Arnold着色器。
我做错了什么?
发布于 2010-07-31 06:17:27
像这样试一下:
for (it = ArnoldNodes.begin() ; it != ArnoldNodes.end(); ++it)
{
std::cout << "initialize shader " << *it << std::endl;
}printf不适用于std::string,您需要使用cout (或将其传递给迭代器it->c_str())std::string),最好使用it != vec.end() (因为您只需要检查相等性,而不是比较)和++it来递增(对于某些迭代器,后递增可能效率较低)。发布于 2010-07-31 06:10:53
不能使用printf (或任何varargs方法)打印std::string。g++在这里给出一个警告:
warning: cannot pass objects of non-POD type ‘struct std::string’ through ‘...’; call will abort at runtime只需使用cout:
std::cout << "initialize shader " << *it << std::endl;发布于 2010-07-31 06:13:57
另一种可能是使用printf打印与std::string对应的C字符串,如下所示:
printf("initialize shader %s\n", it->c_str());https://stackoverflow.com/questions/3375710
复制相似问题