Thread: String Convert to Char ?

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    4

    Question String Convert to Char ?

    Hi..
    I'm using Visual C++
    in my text box i assign a CString variable
    and i want to convert it to integer. How can i do it ?
    CString = "5+5*5"
    converts to
    int = 5+5*5


    actually i have assign a int variable to the textbox
    but when i insert 5+5, the int variable only contain 5 not 5+5.

    Please help me, and thanks you very much.
    i'm planning to make a calculator for my course's project.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    4
    Well i already tries atoi() but it just didn't work.
    i think it can't convert the arithmatic operator (-,+,*,/)
    plssss help me...

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. The solution to this calculator problem is simple; however, there is a considerable amount of coding involved. Here is one algorithm.

    - extract text from editbox into a string object or CString object
    - enter a for-loop
    - if isdigit(myString[i])...

    Note: There are numerous ways to determine the exact integer before the "+, -," etc. signs. Anyways, you will need to implement one algorithm to extract the exact integer before the a sign in during this step.

    - this next character must be a sign. Enter a switch and determine what mathematical sign the user has entered.

    - push the character into a queue
    - final step: run a for loop and carry out the addition, subtraction, etc.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. "Operator must be a member function..." (Error)
    By Magos in forum C++ Programming
    Replies: 16
    Last Post: 10-28-2002, 02:54 PM