Hello everyone I'm having trouble writing part of a vector to a file. I'm getting this error:

main.cpp:287: error: cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `const char*' for argument `2' to `int fprintf(FILE*, const char*, ...)'

This is part of my code:

ListViewTextItem.begin();
FILE * pFile;
  pFile = fopen ("myfile.txt","w");
for( int i = 0; i < ListViewTextItem.size(); i++ ) {
fprintf(pFile, ListViewTextItem[i] );
 }
fclose (pFile);

What's the problem with and how do I fix it???

What kind of an object is ListViewTextItem?

The second argument to fprintf() is a char*, not a c++ class. fprintf() doesn't know a thing about c++ or objects.

Since this is a C++ program, use the C++ I/O mechanisms.

Or to fix the immediate line of code. fprintf(pFile, ListViewTextItem[i].c_str() );

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.