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

You guys were very helpful yesterday. I am still a bit confused here though.
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I am very confused over something and was wondering if someone could explain. In
I am a little confused as to how passing pointers works. Let's say I
...I'm a little confused, or unsure about how to deal with errors that arise
I've been learning about the Model-View-Controller paradigm (MVC), but I'm quite confused since some
Very simply put: I have a class that consists mostly of static public members,
Very often when working on an ASP.NET web site, the options View Code and
Very simple question, is there any cloud server enviroments avaliable these days for us
Very basic question: how do I write a short literal in C++? I know

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.