Is there any particular problem in converting these kind of code into VS2010(I have to know before I can check it)
Is there any online VS2010 compiler?
What does assert(false); does?
EXAMPLE
int applyOperator(Operator op,int x,int y)
{
switch (op) {
case operator_plus: return x+y; // jesli operator_plus zwroc x + y itd.
case operator_minus: return x-y;
case operator_mul: return x*y;
case operator_div: return x/y;
case operator_none:
break;
}
assert(false);
return 0;
}
#include <iostream>
using namespace std;
#include <iostream>
#include <string>
class Student {
public:
string Name, ID, Gender, BirthDate, Major;
friend istream& operator >> (istream& in, Student& s); //DEKLARACJA przeciazenia operatora >> tak bay wczytywal dane linia po linii
friend ostream& operator<< (ostream&,Student const&); //DEKLARACJA przeciazenia operatora << tak aby wypisywal obiekty typu Student
};
istream& operator >> (istream& in, Student& s){
cout << "Name\n";
getline (cin,s.Name); //wczytanie linii na imię
cout <<"ID\n";
getline (cin,s.ID); //wczytanie linii na ID
cout <<"Gender\n";
getline (cin,s.Gender);
cout <<"BirthDate\n";
getline (cin,s.BirthDate);
cout <<"Major\n";
getline (cin,s.Major);
return in;
};
ostream& operator<< (ostream &wyjscie, Student const& ex)
{
wyjscie<<""<<"Name:\t"<<ex.Name<<"\n"<<
""<<"Student ID:\t"<<ex.ID<<"\n"<<
""<<"Gender:\t"<<ex.Gender<<"\n"<<
"BirthDate:\t"<<ex.BirthDate<<"\n"<<
"Major:\t"<<ex.Major<<endl;
return wyjscie;
}
int main(){
Student s;
cin>>s;
cout<<s;
return 0;
}
It opens an assert window. It’s a mechanism to let the programmer know when a control path that wasn’t supposed to be reached, is, or a condition that wasn’t supposed to fail, does.
Basically like:
When
xis0, the program would normally crash. By checking beforehand, you prevent the crash, but can hide some wrong functionality becausexisn’t supposed to be 0. So you put an assert there to inform you wheneverxis 0.Alternitively, it could be
assert(x), which only triggers ifx==0.