Hello everyone,
I am currently working with Stroustrup's Book "Programming Principles & Practice Using CPP". At the moment, I am at Chapter 6, "Writing a program".
The main task is to write a calculator using tokens, among others.
I'm using the code below. I can compile it, but when I run the programm, I can't basically do anything. I expected, because of while (cin), that I can give as much input by the keyboard as possible, but if I start the programm, it does'nt react to my input.
https://s32.postimg.org/m93oeecn9/cpp_prob.png
After a certain time (approx. one or two minutes) an abortion message pops up.
If I add, for instance, something like "cout << "b"; in the code, it just prints out "b" in a infinite circle, which makes sense to me.
So actually, I am not sure whether it's because of my code or of my computer/compiler. I am using VisualStudios2015 on Win7_32, x86.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <fstream>
using namespace std;
class Token {
public:
char kind; // what kind of token
double value; // for numbers: a value
};
Token get_token()
{
return Token();
} // i added "return Token" by myself, as the compiler gave out an error before
vector<Token> tok; // we’ll put the tokens here
int main()
{
while (cin) {
Token t = get_token();
tok.push_back(t);
}
for (int i = 0; i<tok.size(); ++i) { //multiplication
if (tok[i].kind == '*') {
double d = tok[i - 1].value*tok[i + 1].value;
}
}
return 0;
}
|
Thanks in advance,
hrxs1