Find the answer to your Linux question:
Results 1 to 2 of 2
Im new to programming and am making a pretty simple program but cant seem to figure out the error im getting. Here is program and below is long error message. ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    1

    Error when compiling with g++

    Im new to programming and am making a pretty simple program but cant seem to figure out the error im getting.

    Here is program and below is long error message.

    #include <iostream>


    using namespace std;



    int main()
    {
    char DATE; // data variable with 8 characters possible (format expected MM/DD/YY)
    int Q_BOOKS; // Quantity of book variable
    char ISBN; // ISBN number variable input with 80 characters possible
    char BOOK; // Title of book variable with 80 charaters possible
    float PRICE; // Price of book being bought

    cout << "What is the date? (MM/DD/YY)" << endl;
    cin.getline(DATE, 9) >> endl;

    cout << "Number of books being purchases?" << endl;
    cin >> Q_BOOKS >> endl;

    cout << "What is the ISBN number of the book being purchased?" << endl;
    cin.getline(ISBN, 81) >> endl;

    cout << "What is the title of the book being purchased?" << endl;
    cin.getline(BOOK, 81) >> endl;

    cout << "What is the price of the book being purchased?" << endl;
    cin >> PRICE >> endl;

    cout << "SeattleU Booksellers\n\n";

    cout << "Date: " << DATE << endl;
    cout << "Quantity of Book: " << Q_BOOKS << endl;
    cout << "ISBN: " << ISBN << endl;
    cout << "Title: " << BOOK << endl;
    cout << "Price: " << PRICE << endl;

    return 0;
    }



    ------------------------------ERROR MESSAGE----------------------------------------------
    _traits<char>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:186: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:217: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_trai ts<char>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:239: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<c har>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:261: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char _traits<char>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:284: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_tra its<char>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:306: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std: :char_traits<char>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:329: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char >]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:351: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<cha r>]
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/istream.tcc:373: note: std::basic_istrea m<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_trait




    Thanks for the help

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    I think your problem is due to all your ">> endl" after you "cin.gettline"s

    You will also have a few runtime errors if the user enters more than one character for the date, ISBN number or book title as char only takes a single character. If for instance you wanted the variable date to hold 8 characters you would need to declare it as:

    Code:
    char date[8];
    Linux User #453176

Posting Permissions

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