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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:20:03+00:00 2026-06-02T16:20:03+00:00

For any function that is declared to take a char* output parameter, is there

  • 0

For any function that is declared to take a char* output parameter, is there a way to specify the “char” part of s std::string as the function’s output?

I began with:

// EDIT:  ADDED THESE TWO LINES FOR CLARITY

sprintf(buf, "top -n 1 -p %s" , commaSeparatedListOfPIDs.c_str() );
fp = popen(buf, "r");

std::string  replyStr;
char         reply[100];

rc = scanf( fp, "%s", reply );
replyStr = reply;

but that seems a bit, well, clumsy.

So, is there a way to say:

rc = scanf( fp, "%s", &replyStr.c_str() );

or something like that?

Thanks!

  • 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-02T16:20:06+00:00Added an answer on June 2, 2026 at 4:20 pm

    Yes this is possible:

    std::string  replyStr(100, '\0');
    //Requires C++11 (to guarantee that strings hold their characters
    //in contiguous memory), and some way to ensure that the string in the file
    //is less than 100 characters long.
    rc = fscanf( fp, "%s", &reply.front() );
    replyStr.erase(replyStr.find('\0'));
    

    The second condition is very difficult to satisfy, and if it is not satisfied this program has undefined behaviour.

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

Sidebar

Related Questions

Is there any function that do the opposite job of QString::split() . I mean
Is there any equivalent function that returns the character at position X in PHP?
Is there any javascript function that can encrypt data: For example i want to
I want to execute any JavaScript function that is part of a JSON using
is there any function in C++ that calculates a fingerprint or hash of a
Is there any already implemented function that has initialArray, sizeOfInitialArray, outArray, and sizeOfOutArray parameters,
Any function that consists of a return statement only could be declared constexpr and
I have a function that is declared like so: public static string MultiWhereToString(List<WhereCondition<T>> whereConditions)
As in, can I pass cin to any function that accepts an ifstream object?
I would like to have a function that can wrap any other function call.

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.