Tuesday, May 06, 2008

Using STL queue with Structure

// testsafearray.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <comutil.h>
#include <atlsafe.h>

#include <iostream>


#include <list>
#include <iostream>
#include <queue>
#include <deque>

using namespace std ;

typedef struct MyStruct
{
int x;
std::string myString;
}My_Info;


typedef queue<My_Info*> test_queueptr;
typedef queue<My_Info> test_queue;


class myClass
{
public:

myClass()
{
}

void PushMyStructPtr(My_Info* miptr)
{
try_one.push(miptr);
}

void PushMyStruct(My_Info mi)
{
try_two.push(mi);
}

void PopMyStructPtr(My_Info* miptr)
{
My_Info* mi_in = try_one.front();

miptr->myString = mi_in->myString;
miptr->x = mi_in->x;

try_one.pop();
}
void PopMyStruct(My_Info* mi)
{
My_Info mi_in = try_two.front();

mi->myString = mi_in.myString;
mi->x = mi_in.x;

try_two.pop();
}


private:
test_queueptr try_one;
test_queue try_two;


};

int main(void)
{
My_Info ms;
ms.myString = "Hello";
ms.x = 23;

myClass* mc= new myClass();

mc->PushMyStruct(ms);

mc->PushMyStructPtr(&ms);

My_Info msnew,msnewptr;

mc->PopMyStruct(&msnew);

std::cout<<msnew.myString.c_str();

mc->PopMyStructPtr(&msnewptr);

std::cout<<msnewptr.myString.c_str();

std::string myGod = "Dhanesh";
if(myGod.compare("Dhanesh")==0)
{
std::cout<<"Done";
}

std::wstring myWstring = L"Hello";
}