Solved

Cleaning up words inside a map template

Posted on 2004-09-21
6
227 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
Technology Partners: 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!

 
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 11

Expert Comment

by:avizit
ID: 12119202
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 149
SNMP error No Such Object available on this agent at this OID 3 446
Dialogbox API leak? 18 118
COM server issue 2 26
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

738 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