Thread: debug assertion failed: deque iterator not dereferencable

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    30

    debug assertion failed: deque iterator not dereferencable

    code compiles and works if i dont have my cout statement. but when i try to cout the front and top element of queue it compiles but has that debug error

    Code:
    void wordTest(string search, string temp, int i)
    {
    	string word;
    	set<string> myset;
    	set<string>::iterator iter;
    	//string temp;
    	Stack<string> object;
    	queue<Stack<string>> myqueue;
    
    	ifstream infile;
    	infile.open("words.txt");
    
    	while (infile >> word)
    	{
    		myset.insert(word);
    	}
    
    		//cout << search << endl;
    		iter = myset.find(search);
    	
    		if (iter != myset.end())
    		{
    			//Stack<string> object;
    			object.push(temp);
    			object.push(search);			
    			myqueue.push(object);
    		}
    	
    
    	//object.printStack(cout);
    
    
    	cout << myqueue.front().top();
    
    	
    	infile.close();
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Before doing something like myqueue.front(), it is probably a good idea to check myqueue.empty() first. Same thing for your stack.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Also:
    Code:
    queue<Stack<string>> myqueue;
    What compiler are you using? I'm pretty sure mine would get confused by that . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debug Assertion Failed!
    By IndioDoido in forum C Programming
    Replies: 31
    Last Post: 03-25-2008, 11:07 AM
  2. Visual Studio 2005 Debug Assertion Failed
    By natmas in forum C++ Programming
    Replies: 7
    Last Post: 07-17-2007, 04:28 PM
  3. debug assertion failed !
    By blue_gene in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2004, 11:23 AM
  4. Debug Assertion Failed!
    By Ray Schmidt in forum C++ Programming
    Replies: 3
    Last Post: 02-21-2003, 09:58 PM
  5. Debug Assertion Failed
    By minesweeper in forum Windows Programming
    Replies: 5
    Last Post: 12-11-2002, 05:11 PM