472,787 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,787 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 1414
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.