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 40 41
|
#include <iostream>
#include <string> // <--- Added.
#include <limits> // <--- Added.
#include <sstream>
//using namespace std; // <--- Best not to use.
int main()
{ // <--- Moved down to here. makes the program easier to read and easier to find the {}s.
//std::string str;
//getline(cin, str);
//int d = 10, e = 11, f = 12, g = 13, h = 14, i = 15, j = 16, k = 17, l = 18, m = 19, n = 20, o = 21, p = 22, q = 23, r = 24, s = 25;
int num[20]{}; // <--- Best to initialize your variables.
int index{};
std::string output;
while (1)
{
std::cout << "\n Enter a number -1 to quit: ";
std::cin >> num[index++];
if (num[index - 1] == -1) break;
}
for (size_t lc = 0; lc < index-1; lc++)
{
//std::cout << "\n " << static_cast<char> (num[lc]) << std::endl;
// Or could use something like this.
output += static_cast<char>(num[lc]);
output += ", ";
}
std::cout << output << std::endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires heder file <limits>.
std::cout << "\n\n\n\n Press Enter to continue";
std::cin.get();
return 0;
}
|