string typ variables not working

#include <iostream>
#include <string>
using namespace std;
int main ()
string mystring = "This is a string";
cout << mystring;
return 0;
this is my code. why it is not working? i'm using visual studio 2010
thank you.
What errors are you getting?
error is coming from visual studio saying "There were build errors"
And the build errors are?
this is the whole thing showing on output screen
1>------ Build started: Project: first_project, Configuration: Debug Win32 ------
1>Build started 4/8/2013 11:06:55 AM.
1> Touching "Debug\first_project.unsuccessfulbuild".
1> All outputs are up-to-date.
1>using_variables.obj : error LNK2005: _main already defined in first_code.obj
1>J:\c++ programming\first_project\Debug\first_project.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build FAILED.
1>Time Elapsed 00:00:00.99
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
i created two files in same project.
i thought they are working as two separate files. i just remove first file i created with the codes
#include <iostream>
using namespace std;
int main ()
cout << "Hello World! "; // prints Hello
cout << "I'm a C++ program"; // prints I'm a
return 0;
so after that the second one executed without errors.
Do you have multiple cpp files in the project with main()s in them? The error seems to indicate you have another file called using_variables.cpp with a main() in it.

EDIT: Ok, thought so.
Last edited on
yes that was the error.
thank you for helping :)
Topic archived. No new replies allowed.