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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:55:03+00:00 2026-05-21T05:55:03+00:00

I am trying to input a delimited text file with getline but when I

  • 0

I am trying to input a delimited text file with getline but when I debug it it shows me that there is an empty character at the beginning of the variable.

This is only happening with my tID variable which happens to be the first on each line. When I debug it shows this as the character array:

[0] = ”
[1] = ‘2’
[2] = ‘3’
[3] = ‘4’

Here is the relevant code:

ifstream inFile("books.txt");
if (!inFile){
    cout << "File couldn't be opened." << endl;
    return;
}
while(!inFile.eof()){
    string tID, tTitle, tAuthor, tPublisher, tYear, tIsChecked;
    getline(inFile,tID, ';');
    getline(inFile,tTitle, ';');
    getline(inFile,tAuthor, ';');
    getline(inFile,tPublisher, ';');
    getline(inFile,tYear, ';');
    getline(inFile,tIsChecked, ';');
    library.addBook(tID, tTitle, tAuthor, tPublisher, tYear, (tIsChecked == "0") ? false : true);
}

Here are a few lines of book.txt:

123;C++ Primer Plus; Steven Prata; SAMS; 1998;0;
234;Data Structures and Algoriths; Adam Drozdek; Course Technlogy; 2005;0;
345;The Art of Public Speaking; Steven Lucas;McGraw-Hill;2009;0;
456;The Security Risk Assessment Handbook; Douglas J. Landall;Auerbach;2006;1;
  • 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-21T05:55:04+00:00Added an answer on May 21, 2026 at 5:55 am

    Because ; is the delimiter for getline, it doesn’t consume the newline. Add a getline call without an explicitly specified delimiter, or ignore( numeric_limits<streamsize>::max(), '\n' ) to the end of the loop. This has the “bonus” of ignoring data after the last semicolon.

    Bonus diagnostic code: http://ideone.com/u9omo

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

Sidebar

Related Questions

I am trying to read a text file using Dynamics AX. However, the following
Hey I'm trying to perform input validation in PHP to ensure that the stock
I'm trying to receive input from a java dialog and I can't seem to
I'm trying a basic input,output(and append) in C++ here is my code #include <iostream>
I am trying to read a raw input stream from php using php://input .
I'm trying to query database everytime users input messages, nodejs complains Cannot call method
Hi I have been trying to implement auto complete in my site from 2
I'm trying to write a compact update controller for CRUD activity. Here is the
Based on this question which was closed rather quickly: Trying to create a program
I have written a code in Python to create a transition probability matrix from

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.