473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Scratching my head - compiler error with linked list STL

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

Nov 16 '05 #1
2 1427
David Steward wrote:
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>
Why are you including <iostream> and <stdio.h>? Normally, you'd choose one
form of I/O or the other and not mix the two.
#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>(cou t,"\n"));
}

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

-cd

Nov 16 '05 #2
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

-----Original Message-----
David Steward wrote:
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>
Why are you including <iostream> and <stdio.h>?

Normally, you'd choose oneform of I/O or the other and not mix the two.
#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'tjust 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

.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: forgotten field | last post by:
Hi,how are you? I have been studying C++ by myself, but recently I am having a real problem. I am learning about the basic usage of a doubly linked list using polymorphism. However, I have got the...
7
by: OMouse | last post by:
Hi, I just switched to using STL for my linked lists and obviously I need a way to insert. I have all the necessary includes (list & algorithm) and the other functions that I've used (erase & find)...
0
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application...
0
by: Andrew | last post by:
Does a linked list in C require that the head node allocate memory the size of the structures in the node? Or can you just set the head node structure equal to 0? I have tried creating lists both...
3
by: Francois Grieu | last post by:
Given that next is the first field in struct node, and head is a pointer to node, does assigning ((node*)&head)->next safely assign head ? Illustration (this code works on many platforms)...
1
by: lg2530 | last post by:
template<class T> struct NODE { T data; NODE<T> * next; }; template<typename T> NODE<T>* QuickSortList( NODE<T>* list ) {}
6
by: mattmao | last post by:
Okay, this is just my exercise in order to prepare for the coming assignment regarding the damned Linked List issue... The task is simple and I am about to finish it. However, I couldn't go around...
1
by: Lpitt56 | last post by:
I am running MS Access 2007 and I want to update an Outlook Address book from my Access Database. I started out by importing the Outlook Address Book as a linked table and it linked fine. I then...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.