3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by firstPerson
0

A string* is a pointer to an object of type string.

A pointer is typically the size of an int or two, but it's dependent on your system. You can find the size of any object with sizeof.

For example,

string* someStringPointer;
int size = sizeof(someStringPointer);

I suspect you actually want to know the length of a string object, rather than the size of a pointer. If the string object is a std::string, it comes with the member function length() and also size().

string someString("A nice string to use as an exmaple");
int size = someString.size();

If you meant a C-style array of characters, you can use the strlen function, as follows.

/* strlen example */
#include <stdio.h>
#include <string.h>
int main ()
{
  char szInput[256];
  printf ("Enter a sentence: ");
  gets (szInput);
  printf ("The sentence entered is %u characters long.\n",strlen(szInput));
  return 0;
}

Edited by Moschops: n/a

0

Your question is kind of vague, but possible any one of these :

string->size(); //if you are using std::string *
strlen(string); //if you are using c-style string
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.