C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-29-2008, 04:46 AM   #1
Registered User
 
Join Date: Dec 2008
Posts: 18
Question Strings in C++?

Hi Everyone,
I'm new here, so please don't be so harsh on me hehe.

So basically, I went out and purchased "C++ For Dummies, 5th Edition", and read the variables section. It says for strings, you use it in the following format:

Code:
string szMyString;
However, when I put this in, I get a compiler error. I don't think string is recognised as a variable type because it doesn't get highlighted.

So I was wondering, what's going on? Does C++ even support strings? Is there some sort of different header apart from the iostream I need to include?

Oh, happy new year everyone, hope you've all had an excellent Christmas.

Thanks .
sharkbate24 is offline   Reply With Quote
Old 12-29-2008, 04:49 AM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,365
You need to #include <string>. Also, unless you have a using directive like using namespace std; or a using declaration like using std::string;, you should fully qualify the name as std::string.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 12-29-2008, 04:54 AM   #3
Registered User
 
Join Date: Dec 2008
Posts: 18
Quote:
Originally Posted by laserlight View Post
You need to #include <string>. Also, unless you have a using directive like using namespace std; or a using declaration like using std::string;, you should fully qualify the name as std::string.
Thanks a lot!
Have an excellent new year.
sharkbate24 is offline   Reply With Quote
Old 12-29-2008, 04:33 PM   #4
Registered User
 
Join Date: Apr 2006
Posts: 137
The cool thing about strings are that you can even access individual characters like char string arrays, like so: szString[i];

If you need to convert to char array: szString.c_str();
And if you need to cut up sections, use .substr()!

good luck!
__________________
★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★
execute is offline   Reply With Quote
Old 12-30-2008, 03:18 AM   #5
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
That's not cool, that's the biggest headache in trying to produce a std::string-compliant proper unicode-based string implementation.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 12-30-2008, 04:11 AM   #6
Registered User
 
Join Date: Dec 2008
Posts: 18
Nice Thanks guys.
sharkbate24 is offline   Reply With Quote
Reply

Tags
cpp, strings

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings Program limergal C++ Programming 4 12-02-2006 03:24 PM
Programming using strings jlu0418 C++ Programming 5 11-26-2006 08:07 PM
Reading strings input by the user... Cmuppet C Programming 13 07-21-2004 06:37 AM
damn strings jmzl666 C Programming 10 06-24-2002 02:09 AM
menus and strings garycastillo C Programming 3 04-29-2002 11:23 AM


All times are GMT -6. The time now is 07:23 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22