i am getting error in following program. what is "iota". Why it is giving an error in the following program

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  vector<int> V(10);

  iota(V.begin(), V.end(), 7);
  copy(V.begin(), V.end(), ostream_iterator<int>(cout, " "));
  cout << endl; 
  cin.get();
}

Recommended Answers

All 8 Replies

You forgot to #include <numeric>

#include<iostream>
#include<vector>
#include<deque>
#include<list>
#include<algorithm>
#include<functional>
#include<conio.h>
using namespace std;
int main()
{
	vector<int> V1;				 //vector container for integer elements
	deque<int> V2;				 //dequeu container for integer elements
	list<int> V3;				 //list container for integer elements
  
	vector<int>::iterator pos1;		// declaration of iterator
	deque<int>::iterator pos2;		// declaration of iterator		
	list<int>::iterator pos3;		// declaration of iterator
    

	//append elements from 12 to 18 in Vector container V1
	for(int i=12;i<=18;++i)
	{
		  V1.push_back(i);			//inserts an element at the back of the collection
	}

	/*print all elements of V1
     * - iterate over all elements    */
	cout<<"V1:       ";
	for(pos1=V1.begin();pos1!=V1.end();++pos1)
	{
		  cout<<*pos1<<' ';
	}
	cout<<endl;

	
	//append elements from 2 to 8 in deque container V2
	for(int i=2;i<=8;++i)
	{
		  V2.push_front(i);			//inserts an element at the front of the collection
	}
	
	/*print all elements of V2
     * - iterate over all elements    */
	cout<<"V2:       ";
	for(pos2=V2.begin();pos2!=V2.end();++pos2)
	{
		  cout<<*pos2<<' '<<' ';
	}

	cout<<endl;
	int ch;
	do
	{
	cout<<"Select your option\n1.Add\n2.Subtract"<<endl;
	cin>>ch;
	switch(ch)
	{
	case 1: 
			//transform  resulted element to list V3 after addition of each element in vector V1 and deque V2
			 // - Add transformed values
			transform(V1.begin(), V1.end(),				//First sorce range
									V2.begin(),				//Second source range
									back_inserter(V3),		//destination 
									plus<int>());			//operation
				

			//dispaly the resulted output
			cout<<"V1+V2:"<<endl
				;
			for(pos3=V3.begin();pos3!=V3.end();++pos3)
			{	
				cout<<*pos3<<' ';
			}
			/*V3.~list<int>();*/
			V3.clear();
			cout<<endl;
			break;
	case 2: 
			//transform  resulted element to list V3 after addition of each element in vector V1 and deque V2
			// - Add transformed values
			transform(V1.begin(), V1.end(),				//First sorce range
								V2.begin(),				//Second source range
								back_inserter(V3),		//destination 
								minus<int>());			//operation
			

			/* transform (V1.begin(),V1.end(),
										 back_inserter(V3),
										bind2nd (minus<int>(),5)
										);*/
			//dispaly the resulted output
			cout<<"V1-V2:"<<endl;
			for(pos3=V3.begin();pos3!=V3.end();++pos3)
			{	
				cout<<*pos3<<' ';
			}
			/*V3.~list<int>();*/
			V3.clear();
			cout<<endl;
			break;
	default:cout<<"You entered wrong option"<<endl;
			break;
			
	}	
	printf("\nDo you wish to continue[y/n]\n");
    ch=(char)getche();
    }while(ch=='Y' || ch=='y');

	cin.get();
}

How to replace c code of "ch=(char)getche();" into c++ code.

cin >> ch; :-/

> You forgot to #include <numeric> Edward isn't aware of an iota() function in the numeric header, or in the standard library at all. Is that new to C++ 0x?

Edward isn't aware of an iota() function in the numeric header, or in the standard library at all. Is that new to C++ 0x?

From the numeric-header:

#if _HAS_TRADITIONAL_STL
template<class _FwdIt,
	class _Ty> inline
	void iota(_FwdIt _First, _FwdIt _Last, _Ty _Val)
	{	// compute increasing sequence into [_First, _Last)
	_DEBUG_RANGE(_First, _Last);
	for (; _First != _Last; ++_First, ++_Val)
		*_First = _Val;
	}
 #endif /* _HAS_TRADITIONAL_STL */

This function is an SGI extension; it is not part of the C++ standard.

And according to my research (haven't worked with this header) is was original from the algo.h - header

Holy cow! Did I just teach Edward something she didn't know?

That makes my day! :)

There are a lot of things that Edward doesn't know, or forgot, or isn't smart enough to understand. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.