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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:52:45+00:00 2026-06-18T15:52:45+00:00

I am reading an input file line by line by using ifstream and getline

  • 0

I am reading an input file line by line by using ifstream and getline (say in string line). And I have to output string line to a file by removing first character of it. What I am doing is eraseing first character of line and outputting it using ofstream. Is there any better method to do it (means relatively faster one) ? I have millions of strings. (note that this is not true for all the lines, only for first line of every 10 line).

  • 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-18T15:52:46+00:00Added an answer on June 18, 2026 at 3:52 pm

    You could output the actual string pointer plus one:

    outputStream << (line.c_str() + 1);
    

    However, you should better check that the string is not empty first, or you might end up accessing an illegal pointer.

    If you want to output a substring there’s the std::string::substr function. Or use the std::ostream::write function combined with the pointer arithmetic outlined above:

    outputStream.write(line.c_str() + 1, 9);  /* 1st to 10th character */
    

    For the above, you have to make sure the length of the string is at least ten characters.

    Note: I personally would not use “hacks” as the ones outlined in this answer, unless in extreme situations. The substring function is there for a reason, and is the one I would recommend using.

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

Sidebar

Related Questions

I have a multi-line text input file: If the String Log Number: is present,
I'm reading lines from a text file using (line-seq (reader input.txt)) . This collection
I have two C# applications, one is reading a file (File A) line by
I have a program that load data from a file using std::ifstream and store
I am reading the book C++ Primer and at the file input output chapter
I have posted the following code where I am reading from an input file
I was trying to open a file for reading. When using: Scanner input =
I'm using a abstract class in another module for reading and input for my
I have been testing the performance of reading server socket input stream. I found
I'm reading from the standard input using the read() system call but there's a

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.