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 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
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 . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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)...
|
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...
|
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...
|
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)...
|
by: lg2530 |
last post by:
template<class T>
struct NODE
{
T data;
NODE<T> * next;
};
template<typename T>
NODE<T>* QuickSortList( NODE<T>* list )
{}
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
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...
| |