How can I add int to my int array. I do not want to set array size, I do not want to use external loop.
int myArray[] = {};
...
if (condition)
{
myArray.push(value);
}
As Leon suggests what you're looking for is vector and specifically its push_back method.
You could use it as follows:
vector<int> myArray; // currently size 0
if(condition) {
myArray.push_back(value); // now resized to 1;
}
EDIT:
You can use an ostream_iterator to print a vector. For example:
copy(cbegin(myArray), cend(myArray), ostream_iterator<int>(cout, " "))
copy statement, particularly to the multi-lined for-statement, or even worse the single line for-statement.resultArray is empty.size() first.You cannot use push into an array. I would suggest you to use lists or vectors if you don't want to set any size.
std::vector by default.
std::vectorif you need a dynamic array.