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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:52:01+00:00 2026-06-03T11:52:01+00:00

I’m having some trouble dealing with C-style strings in c++. In short what I’m

  • 0

I’m having some trouble dealing with C-style strings in c++. In short what I’m trying to do is pass a cstring from my main method into the constructors of one of my objects.

For example

class sample
{
  public: // Initalization
  Sample( const char * inFile);
}//End sample class

Then in the main method.

//Main method
int main ( int argc, const char * argv[] )
{
   Sample aSample(argv[1]);
}

Now, based on my assumption I should be getting back a const char* when I dereference the second pointer using argv[1]. From my understanding char *argv[] is just another way of saying char **argv.

Also, just to make sure my understanding of const is correct, const char * is saying “this pointer points to a const char” where const char const * is saying ” this pointer address can not be changed, and the address it points to is const as well”.

Update –

Just to clarify this is a two part question.

  1. If the constructor in sample is incorrect for passing a cstring, how can I correct it?
  2. Understanding of const

Updated my incorrect statement above that i dereferenced the “first” pointer when it should have been the “second”. Thank you below for pointing that out.

2nd update –
I’m using argv[1] because I’m receiving information from the command line and argv[0] holds only the path of the executable, which I’m not interested in.

Any help is greatly appreciated.

-Freddy

  • 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-03T11:52:02+00:00Added an answer on June 3, 2026 at 11:52 am

    argv[1] dereferences the second pointer, not the first. You want argv[0]. Arrays in C++ are 0-based.

    Also:

    const char const *
    

    isn’t legal (credits to Benjamin for pointing it out). Both consts are applied to the char in this case. If you want the pointer to be const, you need

    char const * const
    

    or

    const char * const
    

    EDIT:

    Question 1) A CString can take a char* as parameter for the constructor, so it should work.

    Question 2) const binds to the left, unless there’s nothing to the left. So const char and char const are the same. For a const pointer, you need * const, not const *.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.