Page 1 of 1

got a compile error

Posted: Tue Oct 20, 2009 7:44 pm
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 :)

Re: got a compile error

Posted: Tue Oct 20, 2009 7:51 pm
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;

Re: got a compile error

Posted: Tue Oct 20, 2009 8:04 pm
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 :)

Re: got a compile error

Posted: Wed Oct 21, 2009 10:42 am
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)

Re: got a compile error

Posted: Wed Oct 21, 2009 3:39 pm
by killercoder
Thank you very much guys :)

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