Hello, I've just begun my first tutorial. I've writtin out a piece of code identical to the one in the tutorial but when I try to compile and run it it gives me an error( http://i.imagehost.org/view/0883/er ).
Heres my code and then the original:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
#include<string>
usingnamespace std; //introduces namespace std
string yell = "A dragon is coming, take cover!!!";
int main(void)
{
cout<< yell.c_str() <<end1
<< yell.c_str() <<end1
<< yell.c_str() <<end1
<< yell.c_str() <<end1;
system("PAUSE");
return 0;
}
In my code I added the system pause so the command prompt stays open. This works fine if I add it to the original code.
Original Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include<iostream>
#include<string>
usingnamespace std; //introduces namespace std
string yell = "A dragon is coming, take cover!!!";
int main(void)
{
cout<< yell.c_str() <<endl
<< yell.c_str() <<endl
<< yell.c_str() <<endl
<< yell.c_str() <<endl;
return 0;
}
The original compiles just fine but my code which I looked over and over at appears to be identical yet it won't compile.
I'm sorry if this is completely stupid and blatantly obvious but I've been trying to figure this out for an hour or so.
Don't worry, as a fellow beginner, I've also made my share of silly mistakes. The great part about this forum is that the veteran members will take you seriously and help you learn. I'd say this forum has been the most informative part of my whole C++ learning process so far.
I wrote another simple thing here, only thing I couldn't fiqure out how to do is to have it say " x + y = z" so I just made it say "Those two numbers = x".
#include <iostream>
usingnamespace std; //introduces namespace std
int main( void )
{
string pname = "";
int x1;
int y1;
string exit;
cout<< "What is your name?"<< " ";
cin>>pname;
cout<<endl<< "Hello " << pname.c_str() <<endl;
cout<<endl<< "Please give me a number ";
cin>> x1;
cout<< "One more number please ";
cin>> y1;
cout<<endl<< "Those two numbers equal "
<<( x1 + y1 ) << " ! ! " <<endl <<endl;
cout<< "Type and enter anything to exit this great program!";
cin>>exit;
return 0;
}
This is more entertaining then I thought it would be, I should of started doing this long ago! :)