Error with string in "Hello World!"

Hi, i try to make a simple Hello World program using string variable. I compile with Visual Studio 2008 via command prompt, but get an error. What is wrong here?
I know i can make it print Hello World more simple, but i was looking to see how "string" is working.
Note that i am completely new to programming, and if anybody sees an obvious error, i would appreciate an explanation.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main(void)
{
    string myString;
    myString = "Hello World!";

    cout << myString << endl;

    cin.get();
    return 0;
}
you have to include the string libary: #include <string>
Thank you for a quick reply. This solved my problem.
You can still not have the string included and just use std::string cant you?
No, you must include the libary string to be able declaring variables of type string. Yes, it is a standard libary, but (thanks god) not all the standard libary's are automaticly included
So if i do:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>

int main()
{
	std::string myString;
	myString = "Hello World";
	std::cout << myString << std::endl;
	return 0;
}


It will work fine. But if i don't include string and take away my cout. It still compiles fine. Meaning i can still use a string? But I won't be able to display it with the standard libary - unless i include string as well?
Mythios - iostream is probably including string directly or indirectly.
Yeah just as if include iostream and thats all and type std:: - in the intelsence i think its called in visual studio. string is one of the options that will come up. Thus why when i first used strings i was confused as hell why i could pull them up from the standard libary - but when i went to use them I'd have a nice big massive error lol
Topic archived. No new replies allowed.