I have been given the following code as an example to try and compile. Unfortunately I am having issues with it.
#include <list>
#include <iostream>
using namespace std;
int main(int argv, char* argc[])
{
int i;
list<int> 1;
do {
cin >> i;
1.push_back(i);
} while (i!=0);
1.sort();
list<int>::const_iterator iter;
for(iter=1.begin();iter!=1.end();iter++)
cout << (*iter) << endl;
return 0;
}
First I tried the code in eclipse using Linux GCC but I get the following errors:
list.cpp:18:3: error: invalid suffix "push_back" on floating constant
1.push_back(i);
^
list.cpp:21:2: error: invalid suffix "sort" on floating constant
1.sort();
^
list.cpp:24:11: error: invalid suffix "begin" on floating constant
for(iter=1.begin();iter!=1.end();iter++)
^
list.cpp:24:27: error: exponent has no digits
for(iter=1.begin();iter!=1.end();iter++)
^
list.cpp: In function ‘int main(int, char**)’:
list.cpp:15:12: error: expected unqualified-id before numeric constant
list<int> 1;
Changing the language to c++11 I get the following errors:
list.cpp:24:27: error: exponent has no digits
for(iter=1.begin();iter!=1.end();iter++)
^
list.cpp: In function ‘int main(int, char**)’:
list.cpp:15:12: error: expected unqualified-id before numeric constant
list<int> 1;
^
list.cpp:18:3: error: unable to find numeric literal operator ‘operator""push_back’
1.push_back(i);
^
list.cpp:21:2: error: unable to find numeric literal operator ‘operator""sort’
1.sort();
^
list.cpp:24:11: error: unable to find numeric literal operator ‘operator""begin’
for(iter=1.begin();iter!=1.end();iter++)
Is anyone able to shed some light on what is going wrong?
Aucun commentaire:
Enregistrer un commentaire