Click here to Skip to main content
15,888,113 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Managed code *is* slower Pin
Rob Bryce21-Oct-08 8:44
Rob Bryce21-Oct-08 8:44 
QuestionUnmanaged C++ code in managed env error(only framework installled) Pin
balu1234513-Oct-08 21:44
balu1234513-Oct-08 21:44 
AnswerRe: Unmanaged C++ code in managed env error(only framework installled) Pin
Mark Salsbery14-Oct-08 4:09
Mark Salsbery14-Oct-08 4:09 
GeneralRe: Unmanaged C++ code in managed env error(only framework installled) Pin
balu1234514-Oct-08 6:50
balu1234514-Oct-08 6:50 
GeneralRe: Unmanaged C++ code in managed env error(only framework installled) Pin
Mark Salsbery14-Oct-08 7:15
Mark Salsbery14-Oct-08 7:15 
GeneralYou missed one Pin
led mike14-Oct-08 8:05
led mike14-Oct-08 8:05 
GeneralRe: You missed one Pin
Mark Salsbery14-Oct-08 8:12
Mark Salsbery14-Oct-08 8:12 
Questionhelp needed.. STL Pin
wyl8613-Oct-08 0:40
wyl8613-Oct-08 0:40 
i have trouble sorting the name in alphabetical order that i have created.
i've tried the sort function but it does not seem to work.
below are my code:

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>

using namespace std;

class Person
{
private :  
  char *personName;
  long personphonenumber;  
public:  
  Person(char *name, long phoneNumber);
  ~Person();  void PrintPerson();  void PrintFile();
  friend bool operator<(const Person& left, const Person& right);
}; 
bool operator<(const Person& left, const Person& right)
{
  return left.personName < right.personName; 
}
Person::Person(char *name, long phoneNumber){
  personName = new char[sizeof(name) + 1];
  for(int ii = 0; ii <= (sizeof(name) + 1); ii++){
    personName[ii] = name[ii];    personphonenumber = phoneNumber;  }
  cout << "Creating Employee: " << personName << "\t" << "Phone Number: " << personphonenumber << endl;
}
Person::~Person(){  //delete[] personName;
  //cout << "Deleting Employee: " << personName << "\t" << "Phone Number: " << endl;
}
void Person::PrintPerson(){  cout << "----" << endl;
  cout << "Name: " << personName << endl;
  cout << "Phone Number: " << personphonenumber << endl;
  cout << "----" << endl;}void Person::PrintFile(){  fstream oWrite;
  oWrite.open("Data.txt", ios::out | ios::app);
  oWrite << "Name: " << personName << "\t" << endl;
  oWrite << "Phone Number: " << personphonenumber << "\t" << endl;
  oWrite << "\n\n";  oWrite.close();}

int main(int argc, char *argv[])
{  
  char *personName;  
  char name;  
  personName = new char[sizeof(name) + 1];
  long personphonenumber;  
  int nInput;  
  int nNum;  
  bool cont = true;
  Person *personArray;  vector<Person> details;
  vector<Person>::iterator lpi;

while(cont){        
   do{   
      if(cin.fail()){	
      cin.clear();	
      while(cin.get() != '\n');  
   }
      cout << "\nPlease select: \nTo create a new data enter '1' \nTo print the data enter '2' \nTo sort the name in alphabetical order enter '3' \nTo quit enter '4'" << endl;
      cin >> nInput;    }
    while(cin.fail() && cout << "\nPlease enter your selection again.. " << endl);    
    switch(nInput){          
case 1:      
      //for(int ii = 0; ii < details.size(); ii++){
      cout << "Please enter the name: ";      
      cin >> personName;
      cout << endl;      
        do{	
          if(cin.fail()){	 
          cin.clear();
	  while(cin.get() != '\n');	
        }	
        cout << "Please enter the phone number: ";
	cin >> personphonenumber;	cout << endl;      
      }while(cin.fail() && cout << "\nPlease enter again..");
      personArray = new Person(personName, personphonenumber);
      details.push_back(*personArray);
break;      
case 2:            
        for(lpi = details.begin(); lpi != details.end(); ++lpi){
	   lpi -> PrintPerson();	
           lpi -> PrintFile();      
        }     
break;      
case 3:            
      sort(details.begin(), details.end());
      for(lpi = details.begin(); lpi != details.end(); lpi++){
	lpi -> PrintPerson();	
        lpi -> PrintFile();      
      }
break;          
case 4:
  cont = false;
break;         
default:      
          cout << "Invalid input try again" << endl;            
break;
  }  
}  
//delete[] personArray;  //delete[] personName;
return EXIT_SUCCESS;
}

GeneralRe: help needed.. STL Pin
George L. Jackson13-Oct-08 4:28
George L. Jackson13-Oct-08 4:28 
QuestionNumber of controls on the Form. Pin
mikobi12-Oct-08 20:31
mikobi12-Oct-08 20:31 
AnswerRe: Number of controls on the Form. Pin
Lutosław15-Oct-08 12:17
Lutosław15-Oct-08 12:17 
QuestionSplitter, "OnSize strikes back !" Pin
CrocodileBuck11-Oct-08 1:00
CrocodileBuck11-Oct-08 1:00 
AnswerRe: Splitter, "OnSize strikes back !" Pin
Mark Salsbery11-Oct-08 6:27
Mark Salsbery11-Oct-08 6:27 
GeneralRe: Splitter, "OnSize strikes back !" Pin
CrocodileBuck11-Oct-08 7:51
CrocodileBuck11-Oct-08 7:51 
Questionurgent Pin
charusood8-Oct-08 2:53
charusood8-Oct-08 2:53 
AnswerRe: urgent Pin
Mark Salsbery8-Oct-08 7:14
Mark Salsbery8-Oct-08 7:14 
AnswerRe: urgent Pin
Paul Conrad9-Oct-08 7:03
professionalPaul Conrad9-Oct-08 7:03 
QuestionHeader in namespace Pin
piwi1337-Oct-08 22:30
piwi1337-Oct-08 22:30 
AnswerRe: Header in namespace Pin
Mark Salsbery8-Oct-08 7:21
Mark Salsbery8-Oct-08 7:21 
GeneralRe: Header in namespace Pin
piwi1338-Oct-08 22:39
piwi1338-Oct-08 22:39 
GeneralRe: Header in namespace Pin
Mark Salsbery9-Oct-08 5:06
Mark Salsbery9-Oct-08 5:06 
QuestionVisual c++ Net Designer Class disapear [modified] Pin
mikobi7-Oct-08 3:11
mikobi7-Oct-08 3:11 
AnswerRe: Visual c++ Net Designer Class disapear Pin
dybs10-Oct-08 18:56
dybs10-Oct-08 18:56 
GeneralRe: Visual c++ Net Designer Class disapear Pin
mikobi12-Oct-08 19:39
mikobi12-Oct-08 19:39 
AnswerRe: Visual c++ Net Designer Class disapear Pin
leonigah18-Dec-08 22:53
leonigah18-Dec-08 22:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.