|
-
Dec 7th, 2003, 08:46 PM
#1
Thread Starter
Addicted Member
C++ Question on String (Resolved)
But how come i cannot declare String??
There's an error: Undeclared identifier "string"
i have already included string.h
#include <iostream>
#include <fstream.h>
#include <stdlib.h>
#include <STRING>
int main () {
String A;
return 0;
}
Last edited by Shaman; Dec 7th, 2003 at 09:34 PM.
-
Dec 7th, 2003, 08:52 PM
#2
PowerPoster
This is a C# forum, not a C++ one.
But it probably has something to do with the case.
Try
string instead of String
-
Dec 7th, 2003, 09:01 PM
#3
Thread Starter
Addicted Member
it doesnt solve the problem
Thanks
-
Dec 7th, 2003, 09:19 PM
#4
Re: C++ Question on String
Originally posted by Shaman
i have already included string.h
No you haven't. including <string> does NOT guarentee that string.h is included. #include <string>, however, is the correct way.
Originally posted by Shaman
Code:
#include <iostream>
#include <fstream.h>
#include <stdlib.h>
#include <STRING>
int main () {
String A;
return 0;
}
Are you coming from VB? DO NOT USE CAPITALS!!!, C++ is case sensative in everything. An INT is not the same as an int.
To include and use a string:
Code:
#include <iostream>
#include <string>
int main () {
string A;
}
Also, why do you have these in your code?:
Code:
#include <fstream.h>
#include <stdlib.h>
You declare the first header (iostream) correctly, these 2 deprecately and the last 1 incorrectly (capitals).
If you want fstream and stdlib, do this:
Code:
#include <fstream>
#include <cstdlib>
Also, there is a C++ forum here, post C++ questions there. C# is an entirely different language with similar syntax in certain elements.
-
Dec 7th, 2003, 09:34 PM
#5
Thread Starter
Addicted Member
i have found the solution
declaration is :
#include <string.h>
using namespace std;
Its a stupid MS bug!
Thanks
-
Dec 7th, 2003, 09:47 PM
#6
Frenzied Member
Its not a bug. My guess is you are using Managed C++, so you have to use the managed extensions.
-
Dec 8th, 2003, 12:31 AM
#7
Originally posted by Shaman
i have found the solution
declaration is :
#include <string.h>
using namespace std;
Its a stupid MS bug!
Thanks
No, that is a bad solution because that is a deprecate header file. Include <string> not <string.h>.
Because the header is deprecate, it doesn't even use the namespace std, so why did you even declare it?
That isn't an MS bug, I'd suggest a nice C++ book that is caught up with the standard. www.nuwen.net click on C++, go to the bottom and check out the book recommendations. They are all great.
Originally posted by DevGrp
Its not a bug. My guess is you are using Managed C++, so you have to use the managed extensions.
Managed extensions don't mean you use string.h instead of string. string.h is deprecate, he should be using <string>.
-
Dec 8th, 2003, 12:42 AM
#8
Frenzied Member
Originally posted by kasracer
No, that is a bad solution because that is a deprecate header file. Include <string> not <string.h>.
Because the header is deprecate, it doesn't even use the namespace std, so why did you even declare it?
That isn't an MS bug, I'd suggest a nice C++ book that is caught up with the standard. www.nuwen.net click on C++, go to the bottom and check out the book recommendations. They are all great.
Managed extensions don't mean you use string.h instead of string. string.h is deprecate, he should be using <string>.
I was'nt refering to the <string> or <string.h>. I was refering to the using namespace std which is used when writing managed C++.
-
Dec 8th, 2003, 12:53 AM
#9
Originally posted by DevGrp
I was'nt refering to the <string> or <string.h>. I was refering to the using namespace std which is used when writing managed C++.
Uh, no. Managed C++ uses Microsoft's Propritary .NET framework.
The using namespace directive just states that he will be using the namespace std, which is part of the standard C++ libraries.
std has NOTHING to do with managed C++.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|