Teraz mi nie kompiluje. Co może być przyczyną?
Oraz dodatkowe pytanie. Te catche i throwy działają tak dość prymitywnie, tzn catch łapie tego throwa co jest w try tuż nad nim, prawda? Nie ważne jaka nazwa zmiennej będzie? Czy ma być taka sama jak ta throwowana?
W devie działa, w Visualu nie...
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1> d:\programy\microsoft visual studio 11.0\vc\include\ostream(695): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
// zad11.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
try
{
int wiek;
cout << "Powiedz ile masz lat: ";
cin >> wiek;
if(wiek <= 0)
{
string wiad = "Nie mozesz miec tyle lat!";
throw wiad;
}
cout << "Masz " << wiek << " lat" << endl;
}
catch(string wiado)
{
cout << wiado << endl;
}
system("pause");
return 0;
}