I'm making a calculator.
I retrieve the user input from GUI and store it in std::vector<char> c
Now I need to take every char in c
and add it to std::cin
, this is because the calculator engine is based on std::cin
and I just want to add a GUI layer on top.
I wrote some sample code to demonstrate my problem, this is not the actual application:
#include <iostream>
#include <vector>
int main()
{
int length = 6;
std::vector<char> in(length);
in[0] = 'H';
in[1] = 'e';
in[2] = 'l';
in[3] = 'l';
in[4] = 'o';
in[5] = '\0';
for (int i = 0; i < length; ++i)
{
char a = in[i];
std::cout << "a: " << a << std::endl;
std::cin.putback(a);
}
char y = 0;
while(std::cin >> y)
{
std::cout << "y: " << y << std::endl;
if (y == '\0')
{
std::cout << "This is the end!" << std::endl;
}
}
}
My expected result was to get output from the while(std::cin >> y)
loop.
The problem is there is no output.
Edit:
Another way of thinking about my problem is. Let's say I made a program that depended on user input from std::cin
, and the input could be any primary type. Now, if I wanted to test the program by giving it input without shellscripting, how would I do it (from within the program's source)?