What is wrong with this code?

Discussion in 'C++' started by eli m, Mar 5, 2013.

  1. eli m

    eli m Guest

    I am using the dev c++ compiler and i have this code:

    #include <iostream>
    int main ()
    {
    int cmd = 0;
    cout << "Type in help for a list of commands";
    while (cmd == 0) {
    cout << "Type in a function:";
    cin >> function;
    }
    }

    And i got these errors:

    In function `int main()':

    5 `cout' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)

    8 `cin' undeclared (first use this function)

    8 `function' undeclared (first use this function)

    Why am i getting these errors? How am i supposed to do this in c++?
    eli m, Mar 5, 2013
    #1
    1. Advertising

  2. eli m

    Ian Collins Guest

    eli m wrote:
    > I am using the dev c++ compiler and i have this code:
    >
    > #include <iostream>
    > int main ()
    > {
    > int cmd = 0;
    > cout << "Type in help for a list of commands";
    > while (cmd == 0) {
    > cout << "Type in a function:";
    > cin >> function;
    > }
    > }
    >
    > And i got these errors:
    >
    > In function `int main()':
    >
    > 5 `cout' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)
    >
    > 8 `cin' undeclared (first use this function)
    >
    > 8 `function' undeclared (first use this function)
    >
    > Why am i getting these errors? How am i supposed to do this in c++?


    Which book are you using that doesn't tell you cout and cin are in the
    std namespace?

    Why haven't you declared function?

    --
    Ian Collins
    Ian Collins, Mar 5, 2013
    #2
    1. Advertising

  3. eli m

    eli m Guest

    On Monday, March 4, 2013 4:35:35 PM UTC-8, Ian Collins wrote:
    > eli m wrote:
    >
    > > I am using the dev c++ compiler and i have this code:

    >
    > >

    >
    > > #include <iostream>

    >
    > > int main ()

    >
    > > {

    >
    > > int cmd = 0;

    >
    > > cout << "Type in help for a list of commands";

    >
    > > while (cmd == 0) {

    >
    > > cout << "Type in a function:";

    >
    > > cin >> function;

    >
    > > }

    >
    > > }

    >
    > >

    >
    > > And i got these errors:

    >
    > >

    >
    > > In function `int main()':

    >
    > >

    >
    > > 5 `cout' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)

    >
    > >

    >
    > > 8 `cin' undeclared (first use this function)

    >
    > >

    >
    > > 8 `function' undeclared (first use this function)

    >
    > >

    >
    > > Why am i getting these errors? How am i supposed to do this in c++?

    >
    >
    >
    > Which book are you using that doesn't tell you cout and cin are in the
    >
    > std namespace?
    >
    >
    >
    > Why haven't you declared function?
    >
    >
    >
    > --
    >
    > Ian Collins


    Can you explain in more detail please.
    eli m, Mar 5, 2013
    #3
  4. eli m

    Guest

    eli mæ–¼ 2013å¹´3月5日星期二UTC+8上åˆ8時12分39秒寫é“:
    > cout << "Type in help for a list of commands";
    > cout << "Type in a function:";
    > 5 `cout' undeclared
    > 8 `cin' undeclared (first use this function)


    cout and cin are functions defined in namespace std,
    so you should write as "std::cout" and "std::cin".

    > cin >> function;

    in this line you havent declared what "function" is.
    , Mar 5, 2013
    #4
  5. eli m

    eli m Guest

    On Monday, March 4, 2013 8:05:12 PM UTC-8, wrote:
    > eli mæ–¼ 2013å¹´3月5日星期二UTC+8上åˆ8時12分39秒寫é“:
    >
    > > cout << "Type in help for a list of commands";

    >
    > > cout << "Type in a function:";

    >
    > > 5 `cout' undeclared

    >
    > > 8 `cin' undeclared (first use this function)

    >
    >
    >
    > cout and cin are functions defined in namespace std,
    >
    > so you should write as "std::cout" and "std::cin".
    >
    >
    >
    > > cin >> function;

    >
    > in this line you havent declared what "function" is.


    Thank you I figured it out!
    eli m, Mar 5, 2013
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    2,175
    Ralf Hildebrandt
    Sep 10, 2003
  2. willem oosthuizen

    What is wrong with the following code?

    willem oosthuizen, Oct 10, 2003, in forum: VHDL
    Replies:
    9
    Views:
    1,254
  3. Matthew
    Replies:
    7
    Views:
    657
    Priscilla Walmsley
    Jan 7, 2005
  4. David. E. Goble
    Replies:
    9
    Views:
    464
    David. E. Goble
    Feb 2, 2005
  5. kiran
    Replies:
    12
    Views:
    1,100
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page