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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:04:51+00:00 2026-06-10T06:04:51+00:00

I am working on a C/C++ code, that one of the things it does

  • 0

I am working on a C/C++ code, that one of the things it does is replacing a line that has the sentence UNIX_CODE_TOKEN=. I thought I would use system() in order to run sed -i .... Nevertheless, I have noticed that system() is not quite efficient. Thus, I have come to you for good suggestions.

Is there a C/C++ built in function that does the sed -i without using the system()?
Please don’t tell me to use fstream in C++ or the FILE * in C (also fseek and lseek won’t help because I want to replace a specific word in a line),
I decided not to write a function that does the replacement.

Thanks for any help/suggestion/reply.

  • 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-10T06:04:52+00:00Added an answer on June 10, 2026 at 6:04 am

    system() is typically implemented in terms of fork() to split the process, exec() to launch /bin/sh (or whatever) in your child process, and waitpid() in the parent to block until the subshell completes. In your case, you will probably need to implement this yourself, but directly exec() /bin/sed rather than /bin/sh.

    Implementing this correctly is a reasonable amount of work, however. Have you actually benchmarked and profiled your program to determine whether system() is even a performance problem? It’s much more likely that sed is slow – it’s having to access a slow disk, after all – and your investigations are incorrectly fingering system(). You’ll probably find that the fastest way is indeed to process the file directly within your program bit this won’t actually make it much faster overall anyway.

    What is the higher-level problem you’re trying to solve? There’s a good chance that the need to edit a file can be removed completely.

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

Sidebar

Related Questions

I'm working on code that does nearest-neighbor queries. There are two simple ideas that
I'm working with Fortran code that has to work with various Fortran compilers (and
Here is a little background information. I'm working on replacing a dll that has
The code I'm working with has its own smart pointer implementation which does simple
I was working on refactoring some c# code with ReSharper. One of the things
I'm working on code that's supposed to start the screensaver defined by the user
I'm working some code that inserts csv rows into an SQLite database using Python.
I've recently been working with code that looks like this: using namespace std; class
I'm working on some code that reads from a socket, and it goes wrong
I'm working with some code that I've found online and I don't quite understand

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.