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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:55:44+00:00 2026-05-27T09:55:44+00:00

My question is in reference to an assignment that I am working on. It

  • 0

My question is in reference to an assignment that I am working on. It seems like there are multiple ways to approach the assignment.

The program I am writing will be a filter for text files. The purpose of the assignment is to get experience with fstream and getline.

Requirements:

  1. Read one text file (any way possible, doesn’t have to be all at once)
  2. Write to a separate text file (any way possible, can append or write character by character)
  3. It is assumed each sentence ends with a period.
  4. The first letter of each sentence must be uppercase.
  5. Everything besides the first letter of each sentence must be lowercase. (proper nouns too – it’s a trivial example)

I have a working draft of a program that I have written, but getline has is inconsistent in how it is reading my text file. Basically, it will read one line in as a string, which is what I want. As it reads in the second line; however, the program throws a runtime error halfway through the line and Windows shuts it down.

Does getline have a buffer that fills up and needs to cleaned after each line read?

My pseudo code for the program:

  1. Use getline to read in string from line x stopping at a period (.).
  2. Iterate over strings characters, uppercasing the first letter, and then lowercasing the rest.
  3. Read in another string continuing after the last period (.) in the text file.
  4. Repeat until text file read.
  5. Write to second text file.

I am implementing getline this way:

getline(fileIN, str1, '.')

str1 is the string that is read from each line.

Am I using getline correctly? Am I thinking this problem through correctly and efficiently?

* I realized as I was finishing this extended question/section that getline may be utilizing more memory for ‘\r’ or ‘\n’ characters at the ends of lines, or for reasons unrelated to memory, getline is not correctly handling (according to my purposes) sentences that wrap to new lines. Does getline not handle sentence/word wrap well?

Also, is there a way to dynamically specify getline to read the first string up to a period (.) or newline (‘\n’), which ever comes FIRST?

Thank you for your time and consideration.

  • 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-27T09:55:45+00:00Added an answer on May 27, 2026 at 9:55 am

    Yes, you are using getline correctly. Make sure to use it as the condition for your while loop or other conditional:

    while(std::getline(fileIN, str1, '.')) {
        // process str1
    }
    

    and don’t make the mistake that so many others have made of trying to use fileIN.good() or !fileIN.eof() or whatever (this will only lead to headache and heartache).

    The buffer of str1 does not need to be cleaned up by you since it is managed by the string class. It will expand as needed and deallocate itself when the variable goes out of scope. That is one of the reasons why we love the Standard Library classes and think twice before using raw arrays.

    Also, there are no artificial limits placed on the capacity of a string. The only limiting factor is the available memory of the system, so with virtual memory, it can potentially be a little less than 4GB on a 32 bit system or a little less than 264 bytes on a 64 bit system.

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

Sidebar

Related Questions

I'm writing this question with reference to this one which I wrote yesterday. After
This is with reference to the below question: Execute program from within a C
I feel like this question is basic enough to be out there somewhere, but
Quick question... Suppose I have a C# struct that contains a single reference member.
This seems like a silly question but I want to be able to instantiate
(Java question) If I reference a field in an inner class, does this cause
This question builds off of a previously asked question: Pass by reference multidimensional array
In reference to this answer to a Stack Overflow question : what is bench-testing
This is in reference to my other question Auto Clearing Textbox . If I
The question is if a database connection should be passed in by reference or

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.