Solved

variable type used for string

Posted on 1998-10-03
6
194 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
Comment Utility
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
Comment Utility
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
Comment Utility
Looks like answers2000 beat me to it! :-)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:yaelie
Comment Utility
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
Comment Utility
Okay, I suppose that makes sense.  I'm glad I could help!
0
 
LVL 6

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now