0

Hi everybody,

Please excuse the noob question as I am new to STL in C++. I am trying to write a very basic program which uses iota. However my compiler is complaining that iota does not exist in algorithm. Some other forums suggested including <backward/algo.h> as iota could have been depreciated. However my code still does not compile. Can some one take a look?

#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<backward/algo.h>

using namespace std;

int main(){
        vector<int> myVector;
        iota(myVector.begin(), myVector.end(),100);
        copy(myVector.begin(), myVector.end(), ostream_iterator<int>(cout," "));
        cout<<endl;
}

I am using g++ on Ubuntu and my compiler version is 4.4.3

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by mike_2000_17
0

itoa() is in <cstdlib> but is non-standard (meaning it is not implemented by all compilers).

This page shows an example of an alternative method using sprintf().

I'm pretty sure you could also use stringstream.

0

There are two versions of iota: an old non-standard version and the standard version added with C++11. I assume you're trying to use the latter, in which case you need to both have a version of GCC that supports that particular part of C++11 and turn on the -std=c++0x switch.

Unfortunately, I don't remember exactly which version of GCC started supporting iota, but it works just peachy in my version (4.6.0).

0

In the newest standard, this function should be found under the #include <numeric> header. Also, I'm pretty sure that GCC has had this function and header for a long time (they list it as part of their 1998/2003 standard library, although it shouldn't be, to be strict) so it should work, not so sure about MSVC though.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.