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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:14:48+00:00 2026-06-03T09:14:48+00:00

I have changed my code, now while the compilation these errors occur: `check.cpp: In

  • 0

I have changed my code, now while the compilation these errors occur:

`check.cpp: In function ‘int main()’:`

check.cpp:14:55: error: invalid conversion from ‘const char**’ to ‘char* const*’ [-fpermissive]

/usr/include/getopt.h:152:12: error: initializing argument 2 of ‘int getopt(int, char* const*, const char*)’ [-fpermissive]

int main() {

string text="-f  input.gmn -output.jpg";
int argc=text.length();
cout<<"argc: "<<argc<<endl;
char const * argv = text.c_str();
cout<<"argv: "<<argv<<endl;
int c = getopt (argc, &argv, "f:s:o:pw:h:z:t:d:a:b:?");
return 0;
}
  • 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-03T09:14:49+00:00Added an answer on June 3, 2026 at 9:14 am

    You can use text.c_str() to convert a std::string into a const char*. See here.

    To elaborate on my answer, there are many ways to create the array you need, but this is already described here, here, here and here. A simple solution to your problem that does not involve new/malloc or intensive uses of the STL and istringstream/back_inserter/copy what not and performs really fast could look like this:

    /* variables. */
    std::vector< char* > argv;
    int i, argc, state;
    char c;
    
    /* convert string to char string with automatic garbage collection. */
    std::vector< char > tokens(text.begin(), text.end());
    tokens.push_back(0);
    
    /* tokenize string with space. */
    for (state=0, argc=0, i=0; (c=tokens[i]); i++) {
        if (state) {
            if (c == ' ') {
                tokens[i]=0;    
                state=0;        
            }           
        } else {
            if (c != ' ') {
                argv.push_back(&tokens[i]);
                argc++;         
                state=1;        
            }           
        }       
    }   
    
    /* print argv. */
    std::cout << "argc: " << argc << std::endl;
    for (i=0; i < argc; i++) {
        std::cout << "argv[" << i << "]: " << argv[i] << std::endl;
    }   
    
    /* call getopt. */
    c = getopt(argc, &argv[0], "f:s:o:pw:h:z:t:d:a:b:?");
    

    This is just an example, but one advantage of this kind of code is that you can use other characters as delimiter, not just space, and that you need not care about releasing the allocated memory since std::vector does this for you on function exit.

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

Sidebar

Related Questions

I have changed a lot of things in a java code but now I
I have the following code (changed object names, so syntax/spelling errors ignore). public class
I have this working code, but now i need to be able to change
I have following code which works for radio buttons but need to be changed
I have a segmentation fault in the code below, but after I changed it
I have code as follows: $(#item_select).change(function() { var params = $(#item_select option:selected).val(); $.post('/account/ar_form.php', {idata:
[EDIT] I changed my code according to the your answers. But now I get
I am having a problem in the program code as I have changed my
I have changed my previous code so I am not using 'using'. It work
I have been looking around online for a while now for methods of integration

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.