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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:52:45+00:00 2026-05-12T17:52:45+00:00

I am very confused about when to use string (char) and when to use

  • 0

I am very confused about when to use string (char) and when to use string pointers (char pointers) in C++. Here are two questions I’m having.
which one of the following two is correct?

string subString;
subString = anotherString.sub(9);

string *subString;
subString = &anotherString.sub(9);

which one of the following two is correct?

char doubleQuote = aString[9];
if (doubleQuote == "\"") {...}

char *doubleQuote = &aString[9];
if (doubleQuote == "\"") {...}
  • 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-05-12T17:52:45+00:00Added an answer on May 12, 2026 at 5:52 pm

    None of them are correct.

    The member function sub does not exist for string, unless you are using another string class that is not std::string.

    The second one of the first question subString = &anotherString.sub(9); is not safe, as you’re storing the address of a temporary. It is also wrong as anotherString is a pointer to a string object. To call the sub member function, you need to write anotherString->sub(9). And again, member function sub does not exist.

    The first one of the second question is more correct than the second one; all you need to do is replace "\"" with '\"'.

    The second one of the second question is wrong, as:

    1. doubleQuote does not refer to the 10th character, but the string from the 10th character onwards
    2. doubleQuote == "\"" may be type-wise correct, but it doesn’t compare equality of the two strings; it checks if they are pointing to the same thing. If you want to check the equality of the two strings, use strcmp.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everybody, I'm very confused about how to use two different Cell Types in
I am very confused about when I should use '\'. Consider the examples: (1)
I am very confused about how decimal numbers work in perl. I'm having trouble
I am very confused about when and when not to use native queries in
I am really very confused about what is used to represent a string in
I'm very confused about the whole user profile thing in drupal, hope someone can
Ok, I'm now very confused. After my last question had several people comment about
Very confused here, trying out the yuicompressor on a simple javascript file. My js
I am very new to JSF, and I am pretty confused about the best
I'm very confused about this issue and can't understand it.In the Enumerable Documentation, I

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.