got a compile error

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

got a compile error

Post by killercoder »

i got this compile error but im not sure why

Code: Select all

#include <iostream>
#include <stdlib.h>
#include <string>
int main(int argc, char *argv[])
{
    string mystring;
    mystring = "abcdef";
    cout << mystring[2] << endl;
    return 0;
}
here is the error im getting
C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp In function `int main(int, char**)':
6 C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp `mystring' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
7 C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp `cout' undeclared (first use this function)
7 C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp `endl' undeclared (first use this function)
C:\Documents and Settings\Administrator\Desktop\C++ stuff\Makefile.win [Build Error] [main.o] Error 1

im not sure whats wrong with this... please help thank you :)
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: got a compile error

Post by avansc »

killercoder wrote:i got this compile error but im not sure why

Code: Select all

#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;


int main(int argc, char *argv[])
{
    string mystring;
    mystring = "abcdef";
    cout << mystring[2] << endl;
    return 0;
}
here is the error im getting
C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp In function `int main(int, char**)':
6 C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp `mystring' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
7 C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp `cout' undeclared (first use this function)
7 C:\Documents and Settings\Administrator\Desktop\C++ stuff\main.cpp `endl' undeclared (first use this function)
C:\Documents and Settings\Administrator\Desktop\C++ stuff\Makefile.win [Build Error] [main.o] Error 1

im not sure whats wrong with this... please help thank you :)

using namespace std;
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

Re: got a compile error

Post by killercoder »

ahh thank you so much I was copying it right out of the book and the author didn't have that so i thought i wouldn't need it either but i guess i was wrong thanks :)
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: got a compile error

Post by MarauderIIC »

Yep, when you get stuff like (this standard function) undeclared, you're either missing the include or missing the namespace.

`cout' undeclared (first use this function)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

Re: got a compile error

Post by killercoder »

Thank you very much guys :)

I made my second program today I am proud of it too :P
Post Reply