Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


8,120 questions

11,301 answers

573 users

How to initialize alarray with specific elements from other alarray in C++

2 Answers

0 votes
#include <iostream>
#include <valarray>

using std::cout;
using std::endl;

int main()
{
	std::valarray<int> va(15);

	for (int i = 0; i < 15; i++) va[i] = i;

	std::valarray<int> va_part = va[std::slice(2, 3, 5)];

	for (int i = 0; i < va_part.size(); i++)
		cout << va_part[i] << " ";

	cout << endl;

	return 0;
}


/*
run:

2 7 12

*/

 




answered May 15 by avibootz
0 votes
#include <iostream>
#include <valarray>

using std::cout;
using std::endl;

int main()
{
	std::valarray<int> va(20);

	for (int i = 0; i < 20; i++) va[i] = i;

	std::valarray<int> va_part = va[std::slice(2, 4, 5)];

	for (int i = 0; i < va_part.size(); i++)
		cout << va_part[i] << " ";

	cout << endl;

	return 0;
}


/*
run:

2 7 12 17

*/

 




answered May 15 by avibootz
...