Ask your own question, for FREE!
Computer Science 22 Online
OpenStudy (anonymous):

Can anyone explain in simple terms how I can traverse a string to manipulate it element-by-element using pointers in C++??

OpenStudy (anonymous):

I don't really know the way it works in C++, because in C++ the 'default' std::string is a class (or maybe a template, I don't know ) in C, It's accomplished using pointer arithmetic: http://ideone.com/DKZRh

OpenStudy (anonymous):

Ok suppose i have a string and i want to replace all vowels by '#' char str[5]='abcde'; char *str1=str; for(i=0;i<5;i++) { if(*(str1+i)=='a') // give all conditions *(str1+i)='#'; }

OpenStudy (rsmith6559):

http://www.cplusplus.com/reference/string/string/find/ http://www.cplusplus.com/reference/string/string/replace/ and iterating through the vowels should do it.

OpenStudy (bruce1q):

Well, if you are programming in C++, use std::string and don't use pointers into it if you don't have to. A simple example: ... string my_string = "Fred Derf"; for (int x = 0; x < my_string.length(); x++) cout << "I found the letter " << my_string[x] << endl; ... If you are asking this to learn about pointers, then the code might look like this ... const char* my_string = "Fred Derf"; for (const char* c = my_string; *c ; c++) cout << "I found the letter " << *c << endl; ... The second example walks the array of characters until the trailing NULL is found, thus causing the *c expression to be interpreted as "false"

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!