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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:23:15+00:00 2026-06-12T17:23:15+00:00

I have an input stream containing integers and special meaning characters ‘#’. It looks

  • 0

I have an input stream containing integers and special meaning characters ‘#’. It looks as follows:
... 12 18 16 # 22 24 26 15 # 17 # 32 35 33 ...
The tokens are separated by space. There’s no pattern for the position of ‘#’.

I was trying to tokenize the input stream like this:

int value;
std::ifstream input("data");
if (input.good()) {
  string line;
  while(getline(data, line) != EOF) {
    if (!line.empty()) {
      sstream ss(line);
      while (ss >> value) {
        //process value ...

      }
    }
  }
}

The problem with this code is that the processing stops when the first ‘#’ is encountered.

The only solution I can think of is to extract each individual token into a string (not ‘#’) and use atoi() function to convert the string to an integer. However, it’s very inefficient as the majority tokens are integer. Calling atoi() on the tokens introduces big overhead.

Is there a way I can parse the individual token by its type? ie, for integers, parse it as integers while for ‘#’, skip it. Thanks!

  • 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-12T17:23:16+00:00Added an answer on June 12, 2026 at 5:23 pm

    One possibility would be to explicitly skip whitespace (ss >> std::ws), and then to use ss.peek() to find out if a # follows. If yes, use ss.get() to read it and continue, otherwise use ss >> value to read the value.

    If the positions of # don’t matter, you could also remove all '#' from the line before initializing the stringstream with it.

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

Sidebar

Related Questions

I have an input stream, and I want to map to output lines. For
I have been testing the performance of reading server socket input stream. I found
So a FILE stream can have both input and output buffers. You can adjust
I have an input stream from a binary file. I want to create a
Possible Duplicate: Connecting an input stream to an outputstream If I have a method
I have a frame of 22 bytes. The frame is the input stream from
So I have a input stream from which I read a smaller fixed-size buffer
I have in an input stream the complete source code of a class. Is
I have a simple JSP to download a csv file containing Japanese characters. Downloaded
I have an input stream coming form a blackbox (say B). All the messages

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.