Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created November 11, 2011 06:36
Show Gist options
  • Select an option

  • Save draftcode/1357356 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/1357356 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string s("abc\0abc");
cout << s.length() << endl; // 3
cout << distance(s.begin(), s.end()) << endl; // 3
string t("abcdabc");
cout << t.length() << endl; // 7
cout << distance(t.begin(), t.end()) << endl; // 7
t[3] = '\0';
cout << t.length() << endl; // 7
cout << distance(t.begin(), t.end()) << endl; // 7
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment