1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

C++ Help

Discussion in 'Programming' started by Cozmic, Jun 23, 2010.

  1. #1
    Hey,

    I am using Visual C++ 2008 to design a windows form. I have several inputs where I want to user to input some numbers, which I will apply to a formula and then output the result of the calculation. My problem is that I am having trouble converting the values in the input fields to integers so that they can be applied to the formula. I'm relatively new to C++, so I am having a bit of trouble with data type conversion.

    I want to get this->textBox1->Text and store it in the a variable as an integer. How would I do this?
     
    Cozmic, Jun 23, 2010 IP
  2. SwedBo

    SwedBo Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    #include <iostream>
    #include <sstream>
    
    using namespace std;
    
    int main()
    {
      stringstream resultStream(this->textBox1->Text);
      int result;
    
      resultStream >> result;
      cout << "Result: " << result << endl;
      
      return 0;
    }
    Code (markup):
     
    SwedBo, Jun 24, 2010 IP
  3. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #3
    Thanks. I got it to work.
     
    Cozmic, Jun 24, 2010 IP
  4. botmakers

    botmakers Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Do you still need help with this?
     
    botmakers, Jun 25, 2010 IP