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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:43:12+00:00 2026-05-27T02:43:12+00:00

Using C++, I want to generate a file in which I have to add

  • 0

Using C++, I want to generate a file in which I have to add the line number to the end of each line. Some lines end after 13th character, some of them end after 32nd. But the line numbers should be in the end. A line is 80 characters long, the last number of the line should be in the 80th column of the line.

Is there a way to accomplish this? I initialize my file using ofstream, use C++.

  • 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-27T02:43:13+00:00Added an answer on May 27, 2026 at 2:43 am

    Well, here’s one way to go about it using a stringstream:

    #include <iostream>
    #include <iomanip>
    #include <sstream>
    
    using namespace std;
    
    int main() {
        int lineNum = 42;
        stringstream ss;
        ss << setw(80) << lineNum;
        ss.seekp(0);
        ss << "information for beginning of line";
        cout << ss.str() << endl;
        return 0;
    }
    

    Basically sets the stream to right align and pad to 80 chars, lays down your line number, and then seeks to the beginning of the line where you can output whatever you want. If you keep writing a long line of data into the stream you’ll overwrite your line number, of course.

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

Sidebar

Related Questions

I want to generate a hash code for a file. Using C# I would
I am using opencsv to parse text file and generate List<String[]> now I want
I want to generate a list using my django model say I have these
Using C#, I want to generate 1,000,000 files from DB, each record in separate
I have some data generated in MATLAB that I want to process using Perl.
I am using T4 in my project. I have a .tt file which is
I have an XML file in the drawable-folder. I want parse the XML-file using
I have a Plain text file with possibly millions of lines which needs custom
I actually want to generate random password using PHP uniqid() function $randomPassword = uniqid();
i am using the ghostscriptsharp wrapper for c# and ghostscript. I want to generate

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.