Original Post
How would you get the length of a "char *" in C++? For example, how would you know what the length of the following char is? char* string; cin >> string;
std::string foo; // an object, not just a pointercin >> foo; // one wordgetline(cin, foo); // one linefoo.length(); // length of the string, which is a real "string"foo += "bar"; // much more readable than the C equivalent, and probably faster too// (the string implementation will cache the string length, while raw C-style// "strings" have no such concept; the runtime must look up the null terminator// every time)
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more