Solved

Cleaning up words inside a map template

Posted on 2004-09-21
6
232 Views
Last Modified: 2010-04-01
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!
0
Comment
Question by:nothing8171
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 12119130
maybe you can use  

isalpha()  

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

0
 
LVL 1

Author Comment

by:nothing8171
ID: 12119150
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
 
LVL 1

Author Comment

by:nothing8171
ID: 12119183
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 11

Accepted Solution

by:
avizit earned 500 total points
ID: 12119198
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
 
LVL 1

Author Comment

by:nothing8171
ID: 12119259
Thanks avizit!!!  I didn't realize strings act as one-dimensional arrays!!!  Awesome!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question