Solved

variable type used for string

Posted on 1998-10-03
6
195 Views
Last Modified: 2010-04-01
what is the variable type used to represent a string? ie an
entire word rather then just a single letter (char)
0
Comment
Question by:yaelie
  • 4
6 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1174312
an array of chars or a pointer to the start of the string (char *)


/* Array */
char x [] = "Some Text" ;

or

/* Pointer */
char * x = "Some Text" ;

C style strings represent strings terminated with a NUL (character 0)

The standard library includes a type called string which you can use to manipulate stirngs.

MFC (Microsoft Foundation Classes) includes a type called CString which you can also use to manipulate strings
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174313
There is no C++ defined variable for a string.  Perhaps you used to be/are a Basic programmer?  I think there is a string variable in that language.  But in C++ there is not.

You have to use an array of chars.  Here is an example:
char MyString[128] = "Hello world! :-)";

This is the closest you can come to a string.  It may seem overly complicated, but once you get used to it, it's really very easy.  Consider purchasing a book on C++ programming, it would show you all about arrays.

If you want a fairly good, FREE book that you can download off the internet, go to:
http://www.bruceeckel.com/

and download his.  Considering the fact that its free, and still very comprehensive, I highly recommend it.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174314
Looks like answers2000 beat me to it! :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:yaelie
ID: 1174315
Thank you both for the answers...actually, i'm a pascal programmer shark and thats where i got the string from. I know how to do arrays but was wondering if there was an easier way to do it. Thank you for the url though iI'm going to dl the book now.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174316
Okay, I suppose that makes sense.  I'm glad I could help!
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174317
Read the above comment in response to:
>> i'm a pascal programmer
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now