Error : warning: cannot pass objects of non-POD type `struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' through `...';

int main()
{
ListeString Parts;
ListeString::iterator iter;


    Parts.push_back("One");
    Parts.push_back("Two");
    Parts.push_back("Three");

    iter = (*mtcParts)->begin();
    while ( iter1 != (*mtcParts)->end())
    {
           printf("%s\n",*iter1);
            iter1++;
    }
    getchar();
    return 0;
}

By using cout, i am able to get the result but i need to get it with printf. Is it possible?

Thanks in Advance,
Abu

Your post is missing a bit of data, but from what I can see (and without more information, it very well could be swing and a miss) but it looks like Parts is a vector of std::strings. If I'm not mistaken, printf knows nothing of your std::strings, and requires a null terminated array of type char.... You need to convert your std::string to a c-string for printf. I'm not sure if you can just toss a c_str() on your iter1 or not.... I doubt it.

I'm not sure if you can just toss a c_str() on your iter1 or not.... I doubt it.

You're right, that's not possible.

By using cout, i am able to get the result but i need to get it with printf. Is it possible?

The horrible hack to make it work would be this: printf("%s", std::string(*iter).c_str()); but I think the main question is: Why would you want to use printf in a C++ program?

[edit] And I see a few other bugs in your program. Where did iter1 get declared for example?

The horrible hack can be cut by a lot, printf("%s%",iter->c_str()); Still it is a bit ugly, but boost::format and alike solve the obvious problems with iostream, and I agree, don't use printf unless you absolutely have to [mainly because it has runtime type problems]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.