Thread: Odd problem in main(), code won't proceed

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    29

    Odd problem in main(), code won't proceed

    I am writing a really basic program to mimick Sets using linked lists. I just made a small main() to test each of my template functions as I write them. The problem is my main is behaving very oddly and just hanging at certain points everytime I change the code. It wasn't a problem before as I somehow fixed it by putting in cout statements to follow what my code was doing to try and find the hang. After I did this the code would actually run through everything then just hang at the end. Now though no matter what I do I cannot get my code past the line cout<<"3\n"; here it is:

    main.cc
    Code:
    #include "set.h"
    #include <iostream>
    
    using namespace std;
    
    
    int main(void)
    {
    Set <char> newSet;
    newSet.insert('a');
    newSet.insert('b');
    newSet.insert('c');
    newSet.insert('d');
    newSet.insert('e');
    
    cout<<"1\n";
    Set <char> setTwo(newSet);
    cout<<"2\n";
    setTwo.output();
    cout<<"3\n";
    cout<<"Is 'z' in newSet? ";
    if(newSet.is_element('z'))
     cout<<"yes\n";
    else
     cout<<"no\n";
    return (0);
    }
    I'm fairly convinced this has little to with anything outside the main itself since is it hanging in between 2 cout statements where none of my actual functions are being used.

    I ran this code as well and it just does nothing, when i run it it just sits with a blinking cursor, wont take any commands or display anything or ever stop running. The only way to stop it is to close my ssh connection. BTW this is being compiled on a solaris system, when trying to compile on my windows system dev-cpp gives - [Build Error] [Project6.exe] Error 1. In the file Makefile.win.

    main.cc
    Code:
    #include "set.h"
    #include <iostream>
    
    using namespace std;
    
    
    int main(void)
    {
    Set <char> newSet;
    newSet.insert('a');
    newSet.insert('b');
    newSet.insert('c');
    newSet.insert('d');
    newSet.insert('e');
    
    cout<<"Is 'z' in newSet? ";
    if(newSet.is_element('z'))
     cout<<"yes\n";
    else
     cout<<"no\n";
    return (0);
    }
    It is using 4 files total these are:
    node.h - used in many other projects so im fairly confident in it
    set.h - header file for the set template class (attached)
    set.template - template file for set.h (attached as .txt)
    main.cc - where all the problems are

    please any help would be great!!

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Just a quick piece of advice - add a cout << endl or cout << flush after each debug statement you print so that it is flushed to the screen. It is possible that the cout statements have executed but the data has not been flushed to your screen. That might help your debugging (maybe to indicate the problem is in your set code).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  3. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  4. problem with my code
    By stilllearning in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2003, 03:02 PM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM