| | |
Debug Assertion Failed!
Thread Solved
![]() |
•
•
Join Date: Jun 2008
Posts: 92
Reputation:
Solved Threads: 0
I have this error when debugging called Debug Assertion Failed , does anyone know what that means? Im using Visual C++ 2008.
C++ Syntax (Toggle Plain Text)
void merge (string alpha, string beta) { string temp; string temp2; stringstream insert(alpha); stringstream insert2(beta); // Insert the string into a stream ostream_iterator<string> output(cout, " "); vector<string> words; //vector to hold words vector<string> words2; vector<string> results; while (insert >> temp) words.push_back(temp); while (insert2 >> temp2) words2.push_back(temp2); merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin()); cout<<"Merge contains:"; copy(results.begin(), results.end(), output ); }
•
•
Join Date: Jun 2008
Posts: 92
Reputation:
Solved Threads: 0
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?
C++ Syntax (Toggle Plain Text)
void merge (string alpha, string beta) { string temp; string temp2; stringstream insert(alpha); stringstream insert2(beta); // Insert the string into a stream ostream_iterator<string> output(cout, " "); vector<string> words; //vector to hold words vector<string> words2; vector<string> results; while (insert >> temp) words.push_back(temp); while (insert2 >> temp2) words2.push_back(temp2); merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin()); cout<<"Merge contains:"; copy(results.begin(), results.end(), output ); }
Last edited by JackDurden; Sep 17th, 2008 at 11:39 am.
this line is wrong:
You call the function with 5 parameters, but the function only expects 2 (
What is your program supposed to do?
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.
>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:
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:
>You call the function with 5 parameters, but the function only expects 2
Can you say "overloading"?
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:
C++ Syntax (Toggle Plain Text)
merge( words.begin(), words.end(), // OK words2.begin(), words2.end(), // OK results.begin()); // Oops! results is empty
C++ Syntax (Toggle Plain Text)
merge ( words.begin(), words.end(), words2.begin(), words2.end(), back_inserter ( results ) );
Can you say "overloading"?
I'm here to prove you wrong.
•
•
•
•
>You call the function with 5 parameters, but the function only expects 2
Can you say "overloading"?
Silly me, disregard my previous post as it is not worth the space somewhere on a webserver...
•
•
Join Date: Jun 2008
Posts: 92
Reputation:
Solved Threads: 0
The error looks like this:
Debug Assertion Failed!
line 2508
expression: sequence not ordered
And here is my entire code:
Debug Assertion Failed!
line 2508
expression: sequence not ordered
And here is my entire code:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> #include <vector> #include <sstream> #include <algorithm> #include <iterator> using namespace std; //prototype of split function void SplitLines (string& a); void SplitLines2 (string& b); void AunionB (string a, string b); void AinterectB (); void AdifferenceB (); int main() { string fileName; string a; string b; int names = 0; ifstream myfile; cout << "Enter file name: ";// Get filename from user cin >> fileName; myfile.open(fileName.c_str()); while(myfile.good() == false)// Prompt for new file name if not able to open { cout << "Unable to open file. Enter a different name: "; myfile.clear(); cin >> fileName; myfile.open(fileName.c_str()); } while (!myfile.eof()) { getline(myfile,a, '\n'); getline(myfile,b, '\n'); //function call to split lines into words SplitLines(a); cout<<endl; SplitLines2(b); cout<<endl; AunionB (a, b); } myfile.close(); return 0; } //name of fucntion for splitting void SplitLines (string& a) { string temp; stringstream insert(a); // Insert the string into a stream vector<string> words; //vector to hold words while (insert >> temp) words.push_back(temp); cout<<"Set A: {"; for( int i = 0; i < words.size(); i++ ) { cout<< words[i] <<","<< " "; } cout<<"}"; } void SplitLines2 (string& b) { string temp; stringstream insert(b); // Insert the string into a stream vector<string> words; //vector to hold words while (insert >> temp) words.push_back(temp); cout<<"Set B: {"; for( int i = 0; i < words.size(); i++ ) {//print vector to screen cout << words[i] <<","<< " "; } cout<<"}"; } void AunionB (string a, string b) { string temp; string temp2; stringstream insert(a); stringstream insert2(b); // Insert the string into a stream ostream_iterator<string> output(cout, " "); vector<string> words; //vector to hold words vector<string> words2; while (insert >> temp) words.push_back(temp); while (insert2 >> temp2) words2.push_back(temp2); vector<string> results(words.size() + words2.size()); merge(words.begin(), words.end(), words2.begin(), words2.end(), results.begin()); cout<<"Merge contains:"; copy(results.begin(), results.end(), output ); }
![]() |
Similar Threads
- Assertion Failed (C++)
- Debug Assertion Failure (Web Browsers)
- Assertion Failure? (C++)
- File operations (C)
- MFC Listener (C)
- Debug Assertion Failed (Troubleshooting Dead Machines)
- Deleting a pointer? (C++)
Other Threads in the C++ Forum
- Previous Thread: linked lists
- Next Thread: Can't firgure out this compile error
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code codesamplerunwhilecommands coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dissertation dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph guess gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






