PDA

View Full Version : Using ANSI string type



kahahn
20th June 2009, 22:04
I am developing a class for use in under Qt that wants to have public members for converting to and from the ANSI string class. I have

#include <string>
class myClass {

...

public:
string & toString();
void fromString(string & s);
...

};


The VC7 .NET 2003 compiler says: error 2061: syntax error: identifier string

Is there something about compiling in the Qt env that makes the ANSI type, "string", inaccessible? If so, why does the compiler accept the #include? Is there a Qt type I should use instead? :confused:

K.

wysota
20th June 2009, 23:52
It's nothing Qt related. string class is in std namespace, so either place an "using namespace std;" statement somewhere near the beginning of the file or replace all occurences of "string" with "std::string".

Just before you do that, think if that's really what you want - Qt has methods for converting to/from std::string (QString::fromStdString() and QString::toStdString()) so possibly a better approach could be to equip your class with methods that operate using QString and if you need an std string, just use the conversion methods from QString. This would let your class blend better into Qt (if that something you consider worth the trouble).