For initialized variables unsigned a, unsigned bs b > aand std::vector<std::string> stringssize b-a. How can I fill with stringselements, for example. "x3" "x4" "x5" "x6"(in case a=3and b=7) for arbitrary aand bwith one C ++ command (which means one semicolon :))?
unsigned a
unsigned b
b > a
std::vector<std::string> strings
b-a
strings
"x3" "x4" "x5" "x6"
a=3
b=7
a
b
Not too complicated ...
std::transform( boost::make_counting_iterator(a), boost::make_counting_iterator(b), strings.begin(), "x" + boost::lambda::bind(boost::lexical_cast<std::string, unsigned int>, boost::lambda::_1));
What a problem!
while (a < b) strings.push_back('x' + boost::lexical_cast<std::string>(a++));
Also, compare verbosity with Manuel's answer :)
#define IM_NOT_A_SEMICOLON_REALLY ;, .
#define IM_NOT_A_SEMICOLON_REALLY ;
UncleBen, STL
while( a < b ) vStrings.push_back( 'x' + ( (std::stringstream&)( std::stringstream() << a++ ) ).str() );
BOOST_FOREACH(std::string & str, strings) str = "x" + boost::lexical_cast<std::string>(a++);
Violation of semicolon operators that are obviously not a semicolon:
while (a<b) { char s[12], t = (snprintf(s, 11, "x%d", a++), strings.push_back(s), 0); }
Source: https://habr.com/ru/post/1733055/More articles:Setting fill factor to reduce fragmentation - sql-serverprevent recoding captcha - captchaSecurity Integration between ASP.Net and Reporting Services - authenticationLink button with javascript function - javascriptIs it best to use data in a template? - sqlJava: linear algorithm, but non-linear performance drop, where did it come from? - javaiphone monotouch detects that there is an internet connection - iphoneHow to use RtAudio with Direct Sound on windows - audioHow to write quomma - htmlJava array indexing - javaAll Articles