|
-
May 7th, 2001, 06:32 PM
#1
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 7th, 2001, 06:49 PM
#2
Fanatic Member
Try this:
Code:
#include <stdio.h> //Why do you need this for what you are doing?
#include <iostream.h>
#include <string>
std::string sMyStr;
int main()
{
sMyStr = "Hello";
return 0;
}
Alcohol & calculus don't mix.
Never drink & derive.
-
May 7th, 2001, 06:54 PM
#3
You could use char*, which is a string.
Code:
#include <iostream.h>
char* sMyStr;
int main()
{
sMyStr = "Hello";
return 0;
}
-
May 7th, 2001, 08:06 PM
#4
Frenzied Member
It's usually better to use the standard headers. If you use <iostream.h> then a lot of the stuff that's in the standard namespace usually is accessible without taking any notice of namespaces, like cout for instance. I'm not sure whether that's because the M$ header puts you in the standard namespace (instead of the global namespace that is) or because it moves some things from the standard namespace into the global namespace, but... well anyway it makes things unclear.
So, use the standard headers and explicitly resolve the scope:
Code:
#include <cstdio> //I don't know why you need this either
#include <iostream>
#include <string>
std::string sMyStr;
int main()
{
sMyStr = "Hello";
return 0;
}
or, alternatively, use the standard namespace instead of the global namespace, so that the scope becomes implicit:
Code:
#include <cstdio> //I don't know why you need this either
#include <iostream>
#include <string>
using namespace std;
string sMyStr;
int main()
{
sMyStr = "Hello";
return 0;
}
namespaces can make things confusing, but they're pretty fly when you need them. They save all kinds of hassle in big projects and reusable code.
Harry.
"From one thing, know ten thousand things."
-
May 8th, 2001, 05:37 PM
#5
Fanatic Member
Why would they make their own header if the standard one is basically the same thing? Like you said, it would only serve to confuse people.
Alcohol & calculus don't mix.
Never drink & derive.
-
May 8th, 2001, 06:57 PM
#6
Frenzied Member
Yes, it would be unlike Microsoft to make something non-standard wouldn't it?
Harry.
"From one thing, know ten thousand things."
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
|