Cleaning up words inside a map template

Hello everybody,

I am reading words into a map template and while reading them in I have to check to make sure they are all correct without any punctuation marks in them.  If a word comes in that looks like this:     --hello      , then I need to get rid of the -- and just have the hello remain.  I am new to c++ so I was looking for suggestions......My get_words function is below and it's working!!!  Thanks jkr!


unsigned get_words(map<string,unsigned>& rMap)
{

      string word;
      int count = 0;

      while (cin >> word)
      {
      
          rMap[word]++;
          count++;
      }
   
      return (count);
}


Any suggestions would be extremely helpful!
LVL 1
nothing8171Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
avizitConnect With a Mentor Commented:
strings can be subscripted like arrays .

so you can use that  ..
see the folllowing example program to get a hint on how to break up a string into individual characters

#include <iostream>

#include <string>
using namespace std;

int main(){

  string str = "experts-exchange";

  for (unsigned int i = 0; i < str.length(); i++){
    cout<<str[i]<<endl;
  }
  return 0;
}


++++++++++++++
you can also use iterators etc to iterate through the characters .. that i will leave it for you to read and try on your own

0
 
avizitCommented:
maybe you can use  

isalpha()  

 on each character of the word to see if its alphabetic , if not you just discard that character

0
 
nothing8171Author Commented:
Yeah, I came across that method and figured it would be the most appropriate, but it only takes one character as an argument.  How do I break down the word to send each individual character into it?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
nothing8171Author Commented:
I also found that I could use an index variable and set it to the first character in the word, but I don't understand how this works?  I do with arrays, but not individual words.
0
 
nothing8171Author Commented:
Thanks avizit!!!  I didn't realize strings act as one-dimensional arrays!!!  Awesome!
0
All Courses

From novice to tech pro — start learning today.