The following program is giving error as follows. please get me the solution how to debug this error.
Error:
Debug Assertion Failed!

Program: ...
File: d:\program files\microsoft visual studio 8\vc\include\vector
Line: 1556

Expression: ("this->_Mycont != NULL && this->_Myptr != NULL", 0)

#include<iostream>
#include<vector>
#include<deque>
#include<list>
#include<algorithm>
#include<functional>
#include "print.hpp"
int main()
{
	vector<bool> vin1;
	vector<bool> vin2;
	vector<bool> vout;

	cout<<"Enter the value of vin1 in binary\n";
	for(int i=1;i<=8;++i)
	{
		cin>>elem;
		vin1.push_back(elem);
	}
	cout<<"\nEnter the value of vin2 in binary\n";
	for(int i=1;i<=8;++i)
	{
		cin>>elem;
		vin2.push_back(elem);
	}
                PRINT_ELEMENTS(vin1,"vin1:      ");	
	PRINT_ELEMENTS(vin2,"vin2:      ");					transform(vin1.begin(), vin1.end(),         //Error
				vin2.begin(), vout.begin(),
				logical_and<bool>());
	PRINT_ELEMENTS(vout,"vin1 & vin2: ");
cin.get()
}

The above code won't compile. What is 'elem' ? a bool?
And you missed a semicolon after cin.get()

For other people who want to help: Here's the code from the header (it was discussed in another thread)

#include <iostream>
using namespace std;

template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
{
    typename T::const_iterator pos;

    std::cout << optcstr;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {
        std::cout << *pos << ' ';
    }
    std::cout << std::endl;
}

But to solve your problem:
You have to resize the output vector before you put values in it. So put this: vout.resize(vin1.size()); Right before the transform line.

The above code won't compile. What is 'elem' ? a bool?
And you missed a semicolon after cin.get()

For other people who want to help: Here's the code from the header (it was discussed in another thread)

#include <iostream>
using namespace std;

template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
{
    typename T::const_iterator pos;

    std::cout << optcstr;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {
        std::cout << *pos << ' ';
    }
    std::cout << std::endl;
}

But to solve your problem:
You have to resize the output vector before you put values in it. So put this: vout.resize(vin1.size()); Right before the transform line.

thanks i have put vout.resize(vin1.size()); before transform line. now the code is working fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.