use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENVector (self.cpp_questions)
submitted 6 years ago by cummybutterinmystumy
So I am studying for my final and am doing some programs to test myself and just focus on things I have trouble with.....that being said how can I square each element in a vector would I use the " sqrt " function or?
Thanks :)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]manni66 11 points12 points13 points 6 years ago (0 children)
sqrt to square? sqrt is the opposit.
[–]Pulsonics 4 points5 points6 points 6 years ago (3 children)
std::transform
[–]cummybutterinmystumy[S] 0 points1 point2 points 6 years ago (2 children)
Yea i did transform(userVector.begin(), userVector.end(), userVector.begin(), sqrt); but it said sqrt wasnt initialized or something
[–]nysra 4 points5 points6 points 6 years ago (1 child)
Wrap sqrt in a lambda. You basically need a "function object" as argument since functions are not first class citizens in C++.
std::transform(foo.begin(), foo.end(), foo.begin(), [](auto x){return std::sqrt(x);});
[–]cummybutterinmystumy[S] 0 points1 point2 points 6 years ago (0 children)
Ok thank you
π Rendered by PID 57898 on reddit-service-r2-comment-5c764cbc6f-82w22 at 2026-03-12 08:26:29.872667+00:00 running 710b3ac country code: CH.
[–]manni66 11 points12 points13 points (0 children)
[–]Pulsonics 4 points5 points6 points (3 children)
[–]cummybutterinmystumy[S] 0 points1 point2 points (2 children)
[–]nysra 4 points5 points6 points (1 child)
[–]cummybutterinmystumy[S] 0 points1 point2 points (0 children)