Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // strings and c-strings
- // tested with g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 under Debian Stretch
- #include <iostream>
- #include <string>
- using std::cout;
- using std::endl;
- std::string mk_str() {
- return ">Karl-Heinz-Rumpelstilzchen-Koopmann-van-Wijdenvouwrden-123&456*&^%#:";
- }
- int main ()
- {
- std::string str = mk_str(); // initial string
- const char* cstr = str.c_str(); // notice the `const` qualifier
- cout << "--- TEST ---" << endl;
- cout << " string = '" << str << "'" << endl;
- cout << "c-string = '" << cstr << "'" << endl;
- for(std::size_t i = 0; i <= str.length(); ++i)
- printf("char %3d = '%c'\n", int(cstr[i]), cstr[i]);
- cout << "--- END TEST ---" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement