Without iterating through each element, how do I create an array using new and initialize each element to a certain value?
bool* a = new bool[100000];
Using VS 2008.
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In that case, the only value you can set it to is
falsewith:That said, I’m not sure why you’d think you can’t use a loop. They’re there for a reason. You should just use the ready-made function
fillorfill_n(depending on taste).Note using
new“raw” like that is terrible programming practice. Use astd::vector<bool>*:Or:
*Of course,
std::vector<bool>happens to break the proper container interface so doesn’t actually storebool‘s. If that’s a problem use astd::vector<char>instead.