Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:03:53+00:00 2026-06-11T08:03:53+00:00

I am using getline() function to get ride of special characters and punctuation in

  • 0

I am using getline() function to get ride of special characters and punctuation in a sentence, so that when i display the words contained in the sentence, it does not have any other character beside a-z (or A-Z). The problem is that it gets long, and I don’t think it is really efficient. I would like to know if I can do it in a efficient way. I am using Dev-C++, the code below is in C++. Thanks for your help.

#include <string>
#include <iostream>
#include <ctype.h>
#include <sstream>

using namespace std;



int main()
{
 int i=0;
 char y; 
 string prose, word, word1, word2;
 cout << "Enter a sentence: ";
 getline(cin, prose);

 string mot;
 stringstream ss(prose);


 y=prose[i++];
 if (y=' ')   // if character space is encoutered...


  cout<<endl << "list of words in the prose " << endl;
  cout << "---------------------------"<<endl;
  while(getline(ss, word, y))  //remove the space...
   {

      stringstream ss1(word);      

     while(getline(ss1, word1, ','))  //remove the comma...
       {

          stringstream ss2(word1);  //remove the period
          while(getline(ss2, word2, '.'))
           cout<< word2 <<endl; //and display just the word without space, comma or period.
       }
   }      


     cout<<'\n';
    system ("Pause");
    return 0;
}

#############################output

Enter a sentence: What? When i say: “Nicole, bring me my slippers, and give me m
y night-cap,” is that prose?

list of words in the prose

What?
When
i
say:
“Nicole
bring
me
my
slippers
and
give
me
my
night-cap
”
is
that
prose?

Press any key to continue . . .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:03:54+00:00Added an answer on June 11, 2026 at 8:03 am

    Use std::remove_if():

    std::string s(":;[{abcd 8239234");
    
    s.erase(std::remove_if(s.begin(),
                           s.end(),
                           [](const char c) { return !isalpha(c); }),
            s.end());
    

    If you do not have a C++11 compiler, define a predicate instead of using a lambda (online demo http://ideone.com/NvhKq).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I implement a function that acts like getline( .. ). So my initial approach
I am trying to build a vector using a function that I am calling
I'm using std::getline() to read lines from an std::istream-derived class, how can I move
Using the Redis info command, I am able to get all the stats of
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
i try using window.attachEvent (or addEventListener) to capture js errors my callback function gets
Basically I have a thread reading from c++ std::istream using istream& getline ( istream&
I use this function to get a line of text from a rich edit
The average man does not want to be free. He simply wants to be
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.