Friday, July 31, 2009

I can't seem to create a string type while "using namespace std" in one of my header files.?

First of all, I am a beginner to C++ and have very limited knowledge, so please keep any answers simple as possible. I started a project in Dev-C++ just to put into practice what I learned so far. I have a total of 5 files in this project, but I can't seem to get them to compile. For some reason the 'string' type is not defined in one of my included files, even though I'm "using namespace std" at the top of that file. This file is a header file which contains some global variables and 2 class descriptions. But when I try to compile I get the error message :


'string' does not name a type





Can anyone tell me why I can't use a string type in this file, and how I can fix it. Thanks.

I can't seem to create a string type while "using namespace std" in one of my header files.?
Try using a char array instead. To declare one, do this:





char ArrayName[20];





Replace ArrayName with your variable name, and 20 with the maximum characters you want it to be able to hold. To call it later, you just would use ArrayName (i.e. you don't type the brackets when you call it later).





Also, what's cool with arrays, is that later on you can call just one letter from them, like so:





cout %26lt;%26lt; ArrayName[4];





This would print the 5th character stored in the array. I'm not sure what you need your program to do, but arrays are pretty nifty ^.^





If you need any help with beginner C++, or you would like me to send you some of my old programs (commented to show what each line does), feel free to email me through the link on my profile.
Reply:have you tried using:





#include %26lt;string%26gt;





at the top of your file?


No comments:

Post a Comment