Does anyone use Microsoft's CString class?
//printf style formatingstring StrFormat(char *pszString, ...){ va_list argPtr; //buffer to hold the string - this is a fixed size, but you probably wont run over it char szBuf[32768]; //format the string va_start (argPtr, pszString); vsprintf (szBuf, pszString, argPtr); va_end (argPtr); //set the string to the result of the format return string(szBuf);}
If your using inside a loop you could make szBuf static try and make it a bit faster. If speed isn''t that much of a problem you might as well use stringstream.
I appreciate it..
#include #include using namespace std;int main(int argc, char* argv[]){ string str("Hello"); //create a string containing "Hello" str+= " World"; //append " World" string str2(str); //make a copy of str if(str == str2) //compair (case sensetive) with == cout << "same" << endl; int pos = str.find(''e''); //find the first ''e'' in str cout << "e found at " << pos << endl; int pos2 = str2.find_first_not_of("Hle"); //find the first char that is not ''H'' or ''l'' or ''e'' cout << "found" << str2[pos2] << " at " << pos2 << endl; //use [] to access single chars const char* psz = str.c_str(); //.c_str() returns a char* cout << psz << endl; str = ""; if(str.empty()) //true if str is empty cout << "str is empty" << endl; cout << "str2 is " << str2.length() << " letters long" << endl; return 0;}
E:\Projects\VC 6\Font\v2\WinMain.cpp(19) : error C2871: ''std'' : does not exist or is not a namespace
I tried including and , nothing works
Thanks
quote:
E:\Projects\VC 6\Font\v2\WinMain.cpp(19) : error C2871: ''std'' : does not exist or is not a namespace
That looks like a VC error to me, have you tried using the STL that comes with it?
For now, anyways, I''m using and just fine. Thanks for the help.
It''s a clever way to save some space but, IMHO, it''s a pretty minor advantage and will probably save you some space only if you were making a program with a ton of text-handling.
(my byline from the Gamedev Collection series, which I co-edited) John Hattan has been working steadily in the casual game-space since the TRS-80 days and professionally since 1990. After seeing his small-format games turned down for what turned out to be Tandy's last PC release, he took them independent, eventually releasing them as several discount game-packs through a couple of publishers. The packs are actually still available on store-shelves, although you'll need a keen eye to find them nowadays. He continues to work in the casual game-space as an independent developer, largely working on games in Flash for his website, The Code Zone (www.thecodezone.com). His current scheme is to distribute his games virally on various web-portals and widget platforms. In addition, John writes weekly product reviews and blogs (over ten years old) for www.gamedev.net from his home office where he lives with his wife and daughter in their home in the woods near Lake Grapevine in Texas.