Кто объяснит мне, почему символы не отображаются, а вместо них непонятный символ один выводится? Вот код:
#include <iostream>
#include <string>
using namespace std;
class Stack {
private:
int maxSize, top;
char *stack_array;
public:
Stack(char n) {
stack_array = new char[n];
maxSize = n;
top = 0;
} ~Stack() {
delete[]stack_array;
}
void push(char a) {
if (top >= maxSize) {
cout << "Stack is FULL!";
} else
stack_array[top++] = a;
}
int pop() {
if (top == 0) {
cout << "Stack is EMPTY!";
} else
return stack_array[--top];
}
void print() {
for (int i = 0; i < top; i++) {
cout << stack_array[i] << " ";
}
}
char show(char a) {
return stack_array[a - 1];
}
};
int main()
{
system("chcp 1251");
char massiv[20];
int k = 0;
string str = "1 + 2";
for (int j = 0; j < str.length(); j++) {
if (str[j] != '+' && str[j] != '-' && str[j] != '*' && str[j] != '/') {
massiv[k] = str[j];
cout << "\n" << j << ") код=" << (int) massiv[k] << " = " << massiv[k];
k++;
}
}
cout << "\n\n";
system("pause");
return 0;
}