filling up an array in c++
Using C++11
#include <algorithm>
#include <iostream>
int main() {
char array[80];
std::fill(std::begin(array),std::begin(array)+10,'r');
}
Or, as mentioned in the comments you can use std::fill(array,array+10,'r')
.
You can use the []
operator and assign a char
value.
char y[80];
for(int b=0; b<10; ++b)
y[b] = 'r';
And yes, std::fill
is a more idiomatic and modern C++ way to do this, but you should know about the []
operator too!