Link to home
Start Free TrialLog in
Avatar of flexlight
flexlight

asked on

Replace input style (cin to array)

Hi everybody,
I got a code (calculate math expression) from a website and I want to use it in my program.

Part of the code:
"

    cout << "Don't forget add ';' to the tail of the expression:)" <<endl;  

 do
      {
           cin >> temp;
                      if(isdigit(temp))
                    {
                 cin.putback(temp);
                           cin >> number[ntop++];
                      }
...............
      }
      while(temp!=END);
                   
    cout << "And the answer is... " << number[0] <<endl;                    
    return 0;
}
"


In my program I already have an expression (char array) so I don't want to use the "cin" commands (especialy cin.putback) to deal with the expression..
I want to use my array or maybe put the string into cin streaming function(if possible) so I'll can use this code..
Any ideas..?
Thanks for your help.  
ASKER CERTIFIED SOLUTION
Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like you would like to convert your char array to the array of numbers as in the small example.
Would this be helpful:
for(int i=0;...) {
  number[i] = atoi(yourCharArr[i]; //for int atof for double
}
Now you have numbers instead of characters if that was what you tried to achieve
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
  Accept: UrosVidojevic {http:#18013113}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Sean Durkin
Experts Exchange Cleanup Volunteer
Forced accept.

Computer101
EE Admin