strings not working

Jun 30, 2011 at 5:00pm
Hello, as you may know already I am new to the C++ environment. Recently I have been trying to wright a program using strings (shown below) however, it says that "string was undeclared. I am using xcode on OSX 10.6 please help thanks in advance!


1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <stdlib.h>
#include <string>

int main (int argc, char * const argv[]) {
	string mystring;
	mystring = "abcdef";
	cout << mystring[2];
    return 0;
}
Jun 30, 2011 at 5:15pm
Unless you include the std namespace then the name of the datatype is "std::string"
Jun 30, 2011 at 5:16pm
either do

using namespace std; at the beginning.

or use std::string in the code.
Jun 30, 2011 at 9:10pm
just fixed it thanks for the help!
Topic archived. No new replies allowed.