Solved

variable type used for string

Posted on 1998-10-03
6
198 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 68
FMX StringGrid1->Canvas->FillRect Problem 3 153
thread-safe code in c++ 2 103
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 139
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

803 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