Results 1 to 8 of 8

Thread: c++ cin does not work

  1. #1
    Join Date
    Dec 2009
    Beans
    8

    Unhappy c++ cin does not work

    It does not matter which IDE I use for C++, I get an error when I put "cin >> i;" in a source. All of the IDE's: Codelite, Netbeans, and Anjuta are using GNU g++. Codelite gives the errors
    47: error: ‘cout’ was not declared in this scope
    49: error: ‘cin’ was not declared in this scope.

    When I change to Cobra in Codelite, the errors go away. What am I doing wrong?

  2. #2
    Join Date
    Sep 2008
    Location
    Ohio
    Beans
    963
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: c++ cin does not work

    Do you have
    Code:
    #include <iostream>
    using namespace std;
    at the top?

  3. #3
    Join Date
    Dec 2009
    Beans
    8

    Re: c++ cin does not work

    using namespace std; is in the program.

  4. #4
    Join Date
    Dec 2007
    Location
    Edmonton Canada
    Beans
    308
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: c++ cin does not work

    Quote Originally Posted by gwbcomm View Post
    using namespace std; is in the program.
    But is it before your functions? You seem to have a scope issue.
    If at first it doesn't work.. throw a temper tantrum, rant about how it sucks, and hate it forever.

  5. #5
    Join Date
    Nov 2008
    Location
    S.H.I.E.L.D. 6-1-6
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: c++ cin does not work

    Quote Originally Posted by gwbcomm View Post
    It does not matter which IDE I use for C++, I get an error when I put "cin >> i;" in a source. All of the IDE's: Codelite, Netbeans, and Anjuta are using GNU g++. Codelite gives the errors
    47: error: ‘cout’ was not declared in this scope
    49: error: ‘cin’ was not declared in this scope.

    When I change to Cobra in Codelite, the errors go away. What am I doing wrong?
    for some weird reason, in my computer, the C++ libraries are not added properly... but
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include </usr/lib/c++/4.4.1/string>
    #include </usr/lib/c++/4.4.1/iostream>
    Ive included the absolute paths to the libraries just in case.
    Don't waste your energy trying to change opinions ... Do your thing, and don't care if they like it.

  6. #6
    Join Date
    Dec 2009
    Beans
    8

    Re: c++ cin does not work

    my code is below

    #include <stdio.h>


    using namespace std;


    int main ()
    {
    char c;
    int r;
    puts ("Enter text. Include a dot ('.') in a sentence to exit:");
    do {
    c=getchar();
    cin >> r;
    putchar (c);
    } while (c != '.');
    return 0;
    }

    the error is
    :43: error: ‘cin’ was not declared in this scope

  7. #7
    Join Date
    Apr 2007
    Location
    NorCal
    Beans
    1,149
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: c++ cin does not work

    You're mixing C and C++. stdio.h is C's IO library, iostream is C++'s.

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main () {
      string s;
      
      cout << "Say something: ";
      cin >> s;
      cout << "You said: " << s << endl;
    
      return 0;
    }
    Posting code? Use the [code] or [php] tags.
    I don't care, I'm still free. You can't take the sky from me.

  8. #8
    Join Date
    Dec 2009
    Beans
    8

    Re: c++ cin does not work

    you are my hero. I have spent days on the net trying to resolve. I have seen hundreds of posts elsewhere with this problem. I am happy for tonight. maybe now I can continue with my app. Got a way to validate number input (nnnn.nnn)?

    You have a great day

    Thanks

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •