Scratching my head - compiler error with linked list STL

  • Thread starter Thread starter David Steward
  • Start date Start date
D

David Steward

I am really scratching my head on this problem. I am
trying to set up a very simple linked list using the
<list> STL. As an example I wrote sample code just like
what is given in the help files. An example is as follows:

#include "stdafx.h"
#include <iostream>
#include <list>

#include <stdio.h>
#include <stdlib.h>
using namespace System;
using namespace System::IO;
using namespace std;


list<int> intList;

intList.push_back(20);



The problem is that when I compile this, I get compiler
error's C2143, C2501, C2371. It appears that I have all
the header files, but then again I may be wrong.

Help!

David Steward
 
David said:
I am really scratching my head on this problem. I am
trying to set up a very simple linked list using the
<list> STL. As an example I wrote sample code just like
what is given in the help files. An example is as follows:

#include "stdafx.h"
#include <iostream>

#include <list>

#include <stdio.h>
#include <stdlib.h>
using namespace System;

Why is this here - are you trying to make this a .NET application?
using namespace System::IO;
likewise?

using namespace std;


list<int> intList;

intList.push_back(20);

Did you put this code inside a function defintion (e.g. main)? You can't
just dump statements into a .cpp file.
The problem is that when I compile this, I get compiler
error's C2143, C2501, C2371. It appears that I have all
the header files, but then again I may be wrong.


Try this:

#include <list>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

int main()
{
list<int> li;
for (int i = 0; i < 10; ++i)
li.push_back(i);

copy(li.begin(),li.end(),ostream_iterator<int>(cout,"\n"));
}

compile with cl -GX (and any other options you desire).

-cd
 
Sorry for not clarifying,

The code that I showed you was only part of a larger
project. I only included what I thought was necessary to
get the point across.

DAS
 
Back
Top