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

  • Home
  • SEARCH
  • 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 1060635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:21:25+00:00 2026-05-16T18:21:25+00:00

I am curious as to how I would go about reading the input from

  • 0

I am curious as to how I would go about reading the input from a text file with no set structure (Such as notes or a small report) word by word.
The text for example might be structured like this:

“06/05/1992
Today is a good day;
The worm has turned and the battle was won.”

I was thinking maybe getting the line using getline, and then seeing if I can split it into words via whitespace from there. Then I thought using strtok might work! However I don’t think that will work with the punctuation.

Another method I was thinking of was getting everything char by char and omitting the characters that were undesired. Yet that one seems unlikely.

So to sort the thing short:
Is there an easy way to read an input from a file and split it into words?

  • 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-16T18:21:25+00:00Added an answer on May 16, 2026 at 6:21 pm

    Since it’s easier to write than to find the duplicate question,

    #include <iterator>
    
    std::istream_iterator<std::string> word_iter( my_file_stream ), word_iter_end;
    
    size_t wordcnt;
    for ( ; word_iter != word_iter_end; ++ word_iter ) {
        std::cout << "word " << wordcnt << ": " << * word_iter << '\n';
    }
    

    The std::string argument to istream_iterator tells it to return a string when you do *word_iter. Every time the iterator is incremented, it grabs another word from its stream.

    If you have multiple iterators on the same stream at the same time, you can choose between data types to extract. However, in that case it may be easier just to use >> directly. The advantage of an iterator is that it can plug into the generic functions in <algorithm>.

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

Sidebar

Related Questions

I'm curious... how would I go about creating a custom progress bar like the
curious if anyone might have some insight in how I would do the following
I was curious if there's a .Net API that would allow me to identify
I realize this would violate convention, but I'm curious to know if you can
Although I'm specifically interested in web application information, I would also be somewhat curious
Curious to know how people set up their personal and/or work development environment, in
I just finished reading about scoping in the R intro , and am very
I have been reading about creating offline websites using Gears and using HTML 5.
I was reading about cookies and other related client-side storage options, and read about
I was reading the following question - How safe would it be to use

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.