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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:48:16+00:00 2026-05-14T01:48:16+00:00

I have a text file looks like this : 100 50 20 90 4.07498

  • 0

I have a text file looks like this :

100 50 20 90
4.07498 0.074984
37.1704 28.1704
20.3999 14.3999
48.627 35.627 ....

I need to edit this file so that everything is kept the same except the first line, 3rd item. The ouput should look like this:

100 50 19 90
4.07498 0.074984
37.1704 28.1704
20.3999 14.3999
48.627 35.627
....

How can I do it in c++ ? Can anybody help me?

Thanks,
Hoang

  • 1 1 Answer
  • 1 View
  • 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-14T01:48:17+00:00Added an answer on May 14, 2026 at 1:48 am
    #include <stdio.h>
    
    int main()
    {
          FILE *pFile;
          pFile = fopen("example.txt", "r+");
          fseek(pFile, 7, SEEK_SET);
          fputs("19", pFile);
          fclose(pFile);
          return 0;
    }
    

    Edit: The above was of course mostly a joke. The real way to do it is to read the first line, split it into parts, change the required number, write it out, then follow with all the rest of the lines. If we know that the file contains four integers (floats?) on the first line, something like this might suffice:

    #include <fstream>
    #include <iostream>
    using namespace std;
    
    int main ()
    {
        ifstream in("in.txt");
        ofstream out("out.txt");
        float v1, v2, v3, v4;
        in >> v1 >> v2 >> v3 >> v4;
        v3 = 19.1234; // <- Do whatever you need to here.
        out << v1 << " " << v2 << " " << v3 << " " << v4;
        out << in.rdbuf();
        out.close();
        in.close();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks like this. A 102 B 456 C
I have a text file that looks like this: value1 value2 value3 There are
I have a text file that looks like this 1 2 3 4 5
I have a text file that looks like this. I would like to extract
I have a text file, which looks like this: node13 state = free np
I have a text file that looks a bit like: random text random text,
I have a file (called print_1012720.txt ) that looks like the text shown below.
I have 100 text files which look like this: File title 4 Realization number
I have a javascript file that looks like this: if (x > 0 &&
I have a RichTextBox that looks like this: TEXT NEXT_TEXT 10.505 -174.994 0 TEXT

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.