C++: Strings and Characters

STRINGS AND CHARACTER VARIABLES

Page 1 of 1

2 Replies - 543 Views - Last Post: 10 July 2009 - 03:16 PM Rate Topic: -----

#1 RAJIV SINGH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-July 09

C++: Strings and Characters

Post icon  Posted 10 July 2009 - 05:12 AM

Hi i want to know whats the different between string and character variables?
Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: C++: Strings and Characters

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: C++: Strings and Characters

Posted 10 July 2009 - 05:31 AM

String is a C++ class and character is just a single data type for storing a single character.

char[]/char* are faster than using strings but they're also harder to manage (the latter especially) . The string class has certain methods to perform different actions depending on what you're doing, will of course save you some time.
Was This Post Helpful? 0
  • +
  • -

#3 abazaid  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 09-June 09

Re: C++: Strings and Characters

Posted 10 July 2009 - 03:16 PM

the difference between character and string variables,
the character variable take in memory just one byte and we can put in char varible one character like:
char c='A';

but string is a character array termenated by null "\0" like:
char str[6]="dream";
OR
 char* str= new char[6];
str="dream";

remember str[5] is contain null '\0' and also u can write it zero 0
and you can also make that:
 char str[6];
str[0]='d';
str[1]='r';
str[2]='e';
str[3]='a';
str[4]='m';
str[5]=0;

remember str[6] is not exist it a size of array and u can many functions in string.h make many operations on string like:
strcpy,strcmp and strcat and so on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1