Ok, so the problem i have ran into is that the first number (3), is the number of groups, and it can change. And because it can change i got confused how can i declare ints by not knowing how many there will be?
I assume you mean that on each line there are three elements?
In that case, you'll either need to dynamically allocate your array, or just use a std::vector or something; considering that you have a number, assuming this is homework the person who gave it to you probably wants you to do the manual way.
A quick example so you know what you're looking at, and what you might expect you'd need to do to read the file:
1 2 3 4 5 6 7 8 9
std::string** groups = new (std::string*)[numgroups];
// assuming numgroups == 3, dynamically allocate each element:
groups[0] = new std::string[numgroups_group0];
groups[1] = new std::string[numgroups_group1];
groups[2] = new std::string[numgroups_group2];
// make sure to clean up when you're done
for (int i = 0; i < numgroups; ++i)
delete groups[i];
delete groups;
The first value is number-of-groups and is followed by that many "groups".
A "group" has first a number to tell how many entries/lines/rows/triplets will follow and then that many rows.
struct Entry {
// something clever
};
int main() {
using Group = std::vector<Entry>;
std::vector<Group> data;
size_t NG;
std::cin >> NG;
data.reserve(NG);
for ( size_t group = 0; group < NG; ++group ) {
size_t NR;
std::cin >> NR;
Group foo;
foo.reserve(NR);
// read Entries of one group into foo
data.push_back( foo );
}
// use data
return 0;
}
It says how many groups there are. So in this case there will be 3 groups of cats which can contain 2-8 cats. if three would be a const there would be no problem, but that number can change, and there can be more groups
int main () {
constexprint N = 42; // We hope to never have more than this.
double foo_arr[ N ]; // static array
int foo_len;
std::cin >> foo_len;
if ( N < foo_len ) {
// user want's more than we can store. Eject!
std::cout << "Please, recompile the program with a bigger N\n";
return 1;
} else {
for ( int i = 0; i < foo_len; ++i ) {
foo_arr[i] = 3*i;
}
for ( int i = 0; i < foo_len; ++i ) {
std::cout << foo_arr[i] << '\n';
}
}
return 0;
}