4 Apr Also when you search for substring, in C strings you need to check for '\0' on every cycle, in std::string - you don't. In a naive substring search algorithm it doesn't matter much, because instead of checking for '\0' you need to check for istrings in. 14 Jun In my code I'm parsing a long string array and remember it char-by-char in a new array using the CString class like this: CString str; TCHAR c; //Loop str += c; The code above works without a hitch, but when the string array becomes too long (many KBytes) it starts to slow down significantly. I'm guessing. The reason, of course, that C++ programmers prefer the first, slower, syntax is that C++ provides a wonderful mechanism for developers to overload the operatorstring conversions -- not two -- one for builtins and the other for user.
It's going to depend on what you're doing, however, depending on implementation, many actions could be a lot faster in C++ (or any OOP language) than in C. If you've got a C string with 2 million characters, to find the length of that string means strlen() starts at the beginning, and goes through each char, checking if it is. 14 Nov To read a number into an int the library has to convert the ASCII bytes representing the string like "" and run an algorithm on it to convert it into an actual number. This is much more work. The way you measured is probably wrong - file read time varies wildly depending on what is in the disk cache. Stop feeding your C++ compiler C, feed it C++. The stl containers are probably faster than anything you can write. Instead of sprintf use: std::stringstream or if you need unicode std::wstringstream. It works just like cout. If you need it to be converted use the str() method in your application. C strings should.
QString, Python, Java, MFC CString, STL std::string, VStr, firestring, Safe C String Library, c2lib, TR ANSI C0x, Managed Strings ANSI C0x, MS SDK Strsafe. h, libclc. Speed on large strings concat(len=n,len=m), Reasonable O(m), Poor O( n+m), Reasonable O(m), High O(#ops), Unicode O(m), Slow, Slow, Reasonable. Is there a fast way to search for a string in c#? or at least be able to use ststr from c? I have to go through a humongo loop and it takes forever with inde. 10 Sep std::string s0; (); std::string s1="hello"; std::string s2=" "; std::string s3 ="big"; std::string s4=" "; std::string s5="world"; s0=s1.c_str(); s0=s2.c_str(); s0=s3. c_str(); s0=s4.c_str(); s0=s5.c_str();. Here everytime a standard C null-terminated string is assigned. You could think that this is slower, among.