View Single Post
Join Date: Jan 2008
Posts: 3,750
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 491
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Using string as char array

 
0
  #2
Dec 2nd, 2008
Originally Posted by JackDurden View Post
How would I delete one char from a string?

  1. string aWord = "question?";
  2.  
  3. while(aWord[i])
  4. {
  5. if(isalpha(aWord[i]))printf ("character %c is alphabetic\n",aWord[i]);
  6. else
  7. delete[i]aWord;
  8. i++;
  9. }
Use the replace function from string:

http://www.cplusplus.com/reference/s...g/replace.html

  1. string aWord = "abcdef";
  2. aWord.replace (3, 1, "");

aWord now contains "abcef";

Edit: Or just use erase:
  1. aWord.erase (3, 1);

Has the same effect.
Last edited by VernonDozier; Dec 2nd, 2008 at 3:45 pm.
Reply With Quote