Debug Assertion Failed!

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 92
Reputation: JackDurden is an unknown quantity at this point 
Solved Threads: 0
JackDurden JackDurden is offline Offline
Junior Poster in Training

Debug Assertion Failed!

 
0
  #1
Sep 17th, 2008
I have this error when debugging called Debug Assertion Failed , does anyone know what that means? Im using Visual C++ 2008.

  1. void merge (string alpha, string beta)
  2. {
  3. string temp;
  4. string temp2;
  5. stringstream insert(alpha);
  6. stringstream insert2(beta); // Insert the string into a stream
  7. ostream_iterator<string> output(cout, " ");
  8.  
  9. vector<string> words; //vector to hold words
  10. vector<string> words2;
  11. vector<string> results;
  12.  
  13. while (insert >> temp)
  14. words.push_back(temp);
  15.  
  16. while (insert2 >> temp2)
  17. words2.push_back(temp2);
  18.  
  19. merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin());
  20.  
  21. cout<<"Merge contains:";
  22. copy(results.begin(), results.end(), output );
  23.  
  24.  
  25.  
  26. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Debug Assertion Failed!

 
0
  #2
Sep 17th, 2008
The error will also tell you what assertion failed and where it failed. Basically it means you used a library class or function the wrong way, such as passing a null pointer to strcpy.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 92
Reputation: JackDurden is an unknown quantity at this point 
Solved Threads: 0
JackDurden JackDurden is offline Offline
Junior Poster in Training

Re: Debug Assertion Failed!

 
0
  #3
Sep 17th, 2008
ok so since it happened after I put in this function its somewhere in here, do you see any problems with this code that would make that error?

  1. void merge (string alpha, string beta)
  2. {
  3. string temp;
  4. string temp2;
  5. stringstream insert(alpha);
  6. stringstream insert2(beta); // Insert the string into a stream
  7. ostream_iterator<string> output(cout, " ");
  8.  
  9. vector<string> words; //vector to hold words
  10. vector<string> words2;
  11. vector<string> results;
  12.  
  13. while (insert >> temp)
  14. words.push_back(temp);
  15.  
  16. while (insert2 >> temp2)
  17. words2.push_back(temp2);
  18.  
  19. merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin());
  20.  
  21. cout<<"Merge contains:";
  22. copy(results.begin(), results.end(), output );
  23.  
  24. }
Last edited by JackDurden; Sep 17th, 2008 at 11:39 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,834
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Debug Assertion Failed!

 
0
  #4
Sep 17th, 2008
this line is wrong: merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin());

You call the function with 5 parameters, but the function only expects 2 ( void merge (string alpha, string beta)

What is your program supposed to do?
Last edited by niek_e; Sep 17th, 2008 at 11:43 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Debug Assertion Failed!

 
0
  #5
Sep 17th, 2008
>do you see any problems with this code that would make that error?
Yes, and while I'm still miffed that you failed to post the complete text of your error even after I not so subtly informed you that more information is present, I'll tell you what the problem is:
  1. merge(
  2. words.begin(), words.end(), // OK
  3. words2.begin(), words2.end(), // OK
  4. results.begin()); // Oops! results is empty
You need to use some kind of insert iterator to add new items to an empty vector, or you can resize the vector before calling merge:
  1. merge (
  2. words.begin(), words.end(),
  3. words2.begin(), words2.end(),
  4. back_inserter ( results ) );
>You call the function with 5 parameters, but the function only expects 2
Can you say "overloading"?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,834
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Debug Assertion Failed!

 
1
  #6
Sep 17th, 2008
Originally Posted by Narue View Post
>You call the function with 5 parameters, but the function only expects 2
Can you say "overloading"?
Yes I can. Problem is that I forgot that merge() was a function from the C++ Std lib, hence my reply...
Silly me, disregard my previous post as it is not worth the space somewhere on a webserver...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 92
Reputation: JackDurden is an unknown quantity at this point 
Solved Threads: 0
JackDurden JackDurden is offline Offline
Junior Poster in Training

Re: Debug Assertion Failed!

 
0
  #7
Sep 17th, 2008
The error looks like this:

Debug Assertion Failed!
line 2508
expression: sequence not ordered

And here is my entire code:
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <iterator>
  8.  
  9. using namespace std;
  10.  
  11. //prototype of split function
  12. void SplitLines (string& a);
  13. void SplitLines2 (string& b);
  14. void AunionB (string a, string b);
  15. void AinterectB ();
  16. void AdifferenceB ();
  17.  
  18.  
  19.  
  20. int main()
  21. {
  22. string fileName;
  23. string a;
  24. string b;
  25. int names = 0;
  26. ifstream myfile;
  27.  
  28. cout << "Enter file name: ";// Get filename from user
  29. cin >> fileName;
  30.  
  31.  
  32. myfile.open(fileName.c_str());
  33.  
  34.  
  35. while(myfile.good() == false)// Prompt for new file name if not able to open
  36. {
  37. cout << "Unable to open file. Enter a different name: ";
  38. myfile.clear();
  39. cin >> fileName;
  40. myfile.open(fileName.c_str());
  41.  
  42. }
  43.  
  44. while (!myfile.eof())
  45. {
  46. getline(myfile,a, '\n');
  47. getline(myfile,b, '\n');
  48. //function call to split lines into words
  49. SplitLines(a);
  50. cout<<endl;
  51. SplitLines2(b);
  52. cout<<endl;
  53. AunionB (a, b);
  54. }
  55. myfile.close();
  56. return 0;
  57. }
  58. //name of fucntion for splitting
  59. void SplitLines (string& a)
  60. {
  61. string temp;
  62. stringstream insert(a); // Insert the string into a stream
  63.  
  64. vector<string> words; //vector to hold words
  65.  
  66. while (insert >> temp)
  67. words.push_back(temp);
  68. cout<<"Set A: {";
  69. for( int i = 0; i < words.size(); i++ ) {
  70. cout<< words[i] <<","<< " ";
  71. }
  72. cout<<"}";
  73. }
  74. void SplitLines2 (string& b)
  75. {
  76. string temp;
  77. stringstream insert(b); // Insert the string into a stream
  78.  
  79. vector<string> words; //vector to hold words
  80.  
  81. while (insert >> temp)
  82. words.push_back(temp);
  83. cout<<"Set B: {";
  84. for( int i = 0; i < words.size(); i++ ) {//print vector to screen
  85. cout << words[i] <<","<< " ";
  86. }
  87. cout<<"}";
  88. }
  89. void AunionB (string a, string b)
  90. {
  91. string temp;
  92. string temp2;
  93. stringstream insert(a);
  94. stringstream insert2(b); // Insert the string into a stream
  95. ostream_iterator<string> output(cout, " ");
  96.  
  97. vector<string> words; //vector to hold words
  98. vector<string> words2;
  99.  
  100.  
  101. while (insert >> temp)
  102. words.push_back(temp);
  103.  
  104. while (insert2 >> temp2)
  105. words2.push_back(temp2);
  106.  
  107. vector<string> results(words.size() + words2.size());
  108.  
  109. merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin());
  110.  
  111. cout<<"Merge contains:";
  112. copy(results.begin(), results.end(), output );
  113.  
  114. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Debug Assertion Failed!

 
1
  #8
Sep 17th, 2008
Sort your vectors before merging.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC