Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


linked lists

This topic is 5911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

just messin around with linked lists, this code:
#include <fstream.h>

#include <iostream> 

#include <stdio.h> 

#include <string.h> 

#include <conio.h> 

using namespace std; 

class Element { 
   Element (); 
   ~Element (); 
   char *String; 
   Element *Next_Element; 

Element::Element () { 
   String = new char; 

Element::~Element () { 
   delete [] String; 

void main () { 
			ofstream linkedlist("LinkedList.txt");
   char *String_Temp; 
   String_Temp = new char; 

   Element *Element_Temp; 
   Element *First_Element = 0; 
   Element *Last_Element = 0; 

   for (;;) { 
      cout << "Enter a string.\n"; 
      gets (String_Temp); 

      if (strcmp(String_Temp , "stop") == 0) break; 
      Element_Temp = new Element; 

      strcpy (Element_Temp->String , String_Temp); 
      Element_Temp->Next_Element = 0; 

      if (Last_Element) 
         Last_Element->Next_Element = Element_Temp; 
         First_Element = Element_Temp; 

      Last_Element = Element_Temp; 

   if (First_Element) { 
      cout << "Now print the whole list!\n"; 

      Element_Temp = First_Element; 

      do { 

         cout << Element_Temp->String<<endl; 

         Element_Temp = Element_Temp->Next_Element; 

		linkedlist<< Element_Temp->String;

      while (Element_Temp); 

cout << "Press any key to continue!\n"; 

gives me these errors : C:\Windows\Desktop\linkedlists\main.cpp(26) : error C2872: 'ofstream' : ambiguous symbol C:\Windows\Desktop\linkedlists\main.cpp(35) : error C2872: 'cout' : ambiguous symbol C:\Windows\Desktop\linkedlists\main.cpp(54) : error C2872: 'cout' : ambiguous symbol C:\Windows\Desktop\linkedlists\main.cpp(60) : error C2872: 'cout' : ambiguous symbol C:\Windows\Desktop\linkedlists\main.cpp(72) : error C2872: 'cout' : ambiguous symbol i dont get it, could someone help me? [edited by - johnny_blaze93 on August 12, 2002 5:37:33 PM] [/source] [edited by - johnny_blaze93 on August 12, 2002 5:38:00 PM]

Share this post

Link to post
Share on other sites
ok, that cut out the most important part of what i was saying. what i sad was it should be iostream.h instead of just iostream.

Share this post

Link to post
Share on other sites
There''s two problems, one is that you''re mixing old-style with new-style headers. Don''t use the ".h" version of STL headers, they''re not standard. So include <fstream> and not <fstream.h>

The other problem will manifest itself once you can actually compile and run it. The line:

String = new char;

Will create only 1 character, which isn''t what you want. Since you''re using the STL already, I suggest you use the string class, which is a lot simpler.

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

Share this post

Link to post
Share on other sites
Besides #include<string>, there''s also #include <sstream> which lets you create string streams. They work like iostream and/or fstream, expcet they write everything into a std::string.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!