c**y 发帖数: 172 | 1 Something is wrong with "string::iterator p ..."
string accessAString(const string& s) {
string a;
cout << s.c_str() << endl;
for (string::iterator p = s.begin(); p != s.end(); p++) {
cout << *p ;
}
cout << endl;
return a;
} |
w***h 发帖数: 415 | 2 Because you probably should post this question in programming board.
【在 c**y 的大作中提到】 : Something is wrong with "string::iterator p ..." : string accessAString(const string& s) { : string a; : cout << s.c_str() << endl; : for (string::iterator p = s.begin(); p != s.end(); p++) { : cout << *p ; : } : cout << endl; : return a; : }
|
k*p 发帖数: 1526 | 3 s是constant
要用const_iterator
【在 c**y 的大作中提到】 : Something is wrong with "string::iterator p ..." : string accessAString(const string& s) { : string a; : cout << s.c_str() << endl; : for (string::iterator p = s.begin(); p != s.end(); p++) { : cout << *p ; : } : cout << endl; : return a; : }
|
c**y 发帖数: 172 | 4 Thanks a lot. That is what I am looking for.
【在 k*p 的大作中提到】 : s是constant : 要用const_iterator
|
a*********9 发帖数: 523 | 5 正解
【在 k*p 的大作中提到】 : s是constant : 要用const_iterator
|