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 3276294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:14:30+00:00 2026-05-17T19:14:30+00:00

Is it possibile to ignore punctuacion using std manipulator on cin? For example suppose

  • 0

Is it possibile to ignore punctuacion using std manipulator on cin? For example suppose you have an input stream (in the actual case a file) like: “one, two three”. I want to be able to do:

f >> ignore_punct >> a;
f >> ignore_punct >> b;
f >> ignore_punct >> c;

at the end a=="one", b=="two", c=="three".

  • 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-05-17T19:14:31+00:00Added an answer on May 17, 2026 at 7:14 pm

    Try this:

    It uses the local to filter out punctuation.
    This allows the rest of the code to remain unchanged.

    #include <locale>
    #include <string>
    #include <iostream>
    #include <fstream>
    #include <cctype>
    
    class PunctRemove: public std::codecvt<char,char,std::char_traits<char>::state_type>
    {
        bool do_always_noconv() const throw()  { return false;}
        int do_encoding()       const throw()  { return true; }
    
        typedef std::codecvt<char,char,std::char_traits<char>::state_type> MyType;
        typedef MyType::state_type          state_type;
        typedef MyType::result              result;
    
    
        virtual result  do_in(state_type& s,
                const char* from,const char* from_end,const char*& from_next,
                      char* to,        char* to_limit,      char*& to_next  ) const
        {
            /*
             * This function is used to filter the input
             */
            for(from_next = from, to_next = to;from_next != from_end;++from_next)
            {
                if (!std::ispunct(*from_next))
                {
                    *to_next = *from_from;
                    ++to_next;
                }
            }
            return ok;
        }
    
        /*
         * This function is used to filter the output
         */
        virtual result do_out(state_type& state,
                const char* from, const char* from_end, const char*& from_next,
                      char* to,         char* to_limit,       char*& to_next  ) const
        { /* I think you can guess this */ }
    };
    
    
    int main()
    {
        // stream must be imbued before they are opened.
        // Otherwise the imbing is ignored.
        //
        std::ifstream   data;
        data.imbue(std::locale(std::locale(), new PunctRemove));
        data.open("plop");
        if (!data)
        {
            std::cout << "Failed to open plop\n";
            return 1;
        }
    
        std::string         line;
        std::getline(data, line);
        std::cout << "L(" << line << ")\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Ignore SVN files when exporting a WAR file from Eclipse? Using eclipse
Is it possible to have a local Mercurial ignore file? Apparently the .hgignore is
Is it possible to serialize an object using toJson(object) and have the toJson-parser ignore
Is it possible in mercurial to ignore changes within an entire directory. For example
Using bash, is it possibile to send the equivalent of a space bar stroke
Is it possible to ignore the schema in object names when comparing databases using
Is it possible to ignore a specific match in a regular expression? For example:
Possible Duplicate: Mercurial: How to ignore changes to a tracked file I work on
fgetc() and other input functions can return when there's no data on the file
Using Visual Studio, it is possible to 'Ignore Specific Library' (Project Properties > Configuration

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.