arguments

Started by
17 comments, last by FGFS 10 years, 8 months ago

seems so. With:

std::cout << it->second = IFSDatabase::getAppr(QString::fromStdString(it->first));

I get:

..IFSDatabase.cpp:577:22: error: no match for ‘operator<<’ in ‘std::cout << it.std::_Rb_tree_iterator<_Tp>::operator-><std::pair<const std::basic_string<char>, std::vector<Procedure*> > >()->std::pair<const std::basic_string<char>, std::vector<Procedure*> >::second’

Advertisement
it->second is a std::vector<Procedure*> (aka ProcedureList). If you have not overloaded operator<< for that type you will have to loop the vector and print each Procedure object manually.

Something like this:
for (ProcedureList::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
{
	std::cout << (*it2)->toString() << std::endl;
}
If the pointers can be null you'll have to check that too.

Thanks but with that I get:

SDatabase.cpp:580:36: error: no match for ‘operator<<’ in ‘std::cout << Procedure::toString()’

std::cout << (*it2)->toString().toStdString() << std::endl;

Not sure if it's the best way to do it but I think it will should work.

That works but I forgot that I cannot use cout but need a char*

char* ss = (*it2)->toString().toStdString();

tabase.cpp:580:48: error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ in initialization

Thanks again

You can use the .c_str() member function to get a const char * for a std::string. Be careful about storing it as the return value is only valid as long as the std::string exists, so you may need to copy the std::string first and keep it around before using .c_str().

You can use c_str() to get a const char* from a std::string but that pointer will only stay valid for as long as the string is not destroyed/modified.


const char* ss = (*it2)->toString().toStdString().c_str();
doSomethingWith(ss); // ERROR: The data pointed to by ss is no longer valid.

If you just want to pass it to a function on the same line it is OK because the string has not yet been destroyed.


doSomethingWith((*it2)->toString().toStdString().c_str()); // OK

If you want to use it on more than one line you could store the string in a variable to extend the lifetime of the pointer.


std::string str = (*it2)->toString().toStdString();
const char* ss = str.c_str();
doSomethingWith(ss); // OK
doSomethingElseWith(ss); // OK

If you want a non-const char* you can use &str[0] instead of str.c_str().

Works like a charm, thanks.

Now with:

virtual void getIls(const std::string &id, StdWaypointList *list);

declared as:

typedef vector<Waypoint*> StdWaypointList;

I cannot find the StdWaypointList. I only see single waypoints...

Thanks again

This topic is closed to new replies.

Advertisement