Thread: calculator program from Bjarne Stroustrup's book

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Thumbs up calculator program from Bjarne Stroustrup's book

    here is the special edition, page 115, line 23rd:

    while(cin.get(ch)&&isalnum(ch)) string_value.push_back(ch);

    I copied the program from his book, but when I tried to compile, the error messages came out:

    E:\calculator.cpp(55) : error C2039: 'push_back' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'

    Should I include a header file or write the function push_back by myself? Thank you very much.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Sounds like push_back is not implemented in your library. However, push_back is equivelent to the += operator, so you could use that.

    Funny coincidence - I'm writing an RPN calculator myself right now.

  3. #3
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    Here is the full code of the calculator..
    (I learned c++ with that same book too)
    It worked fine for me..

    U might want to rename it dc for argc to work..
    Attached Files Attached Files
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Thumbs up feedback to the help on calculators program

    Thanks Luigi and Davros, it really helps me alot.

    I downloaded Luigi's source code, it doesn't work on my computer
    (Visual C++ 6.0, windows Xp), with the same wrong message:

    c:\documents and settings\cindy\Desktop\calc.cpp(186) : error C2039: 'push_back' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'

    Davros's advice does work.

    good for the coming way

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    2
    Luigi! Dude you use a Mac too? Here I thought I was the only one. I use Proj. Builder too, but it seems to be different then visual C++ in terms of basic commands. Whem I compile my code, everything is ok except one vital thing... It doesn't recognize main(). U know if i'm supposed to do anything different as opposed to its microsoft counterpart?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. URGENT: Help wanted...in C
    By iamjimjohn in forum C Programming
    Replies: 16
    Last Post: 05-18-2007, 05:46 AM
  2. Replies: 5
    Last Post: 09-05-2005, 06:26 AM
  3. Books on C and C++
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-28-2002, 04:18 PM
  4. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 08:03 PM