Storing input to array

I have been working with some code for an assignment, but I can't figure out how to store the user input into an array. So far I have:

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
  #include<iostream>
#include<cstring>
#include <sstream>

int main()
{
	const char comma = ',';
	
	std::cout << "Please enter a sequence of numbers separated by commas on a single line\n";

	std::string line;
	std::getline(std::cin, line); // read the complete line as a string
	std::cout << "you entered: " << line << '\n';

	line += comma; // append a comma at the end; this will make our processing simpler

	std::istringstream strstm(line); // construct a string stream which can read integers from the line

	int number;
	char separator;
	while (strstm >> number >> separator && separator == comma) // for each number read from the line
	{
		const bool divisible_by_3 = number % 3 == 0;
		const bool divisible_by_5 = number % 5 == 0;

		std::cout << number << " - ";

		if (divisible_by_3 && divisible_by_5) std::cout << "FizzBuzz\n";
		else if (divisible_by_3) std::cout << "Fizz\n";
		else if (divisible_by_5) std::cout << "Buzz\n";
		else std::cout << "Please select a different number.\n";
	}
}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/192851/
Topic archived. No new replies allowed.