Program 25
#include
#include
#include
#include
int main(int argc, char* argv[])
{
try
#include
#include
int main(int argc, char* argv[])
{
try
{
if (argc > 1)
if (argc > 1)
{
int value = lexical_cast(argv[1]);
std::string msg;
msg = "the passed value is: "+ lexical_cast(value);
std::cout << msg << std::endl;
}
}
catch (const char* msg)
int value = lexical_cast
std::string msg;
msg = "the passed value is: "+ lexical_cast
std::cout << msg << std::endl;
}
}
catch (const char* msg)
{
std::cerr << "Exception: " << msg << std::endl;
return exit_failure;
}
}
std::cerr << "Exception: " << msg << std::endl;
return exit_failure;
}
}
Program 26
#include
#include
#include
int main()
{
std::ostrstream buffer;
#include
int main()
{
std::ostrstream buffer;
buffer << "Pi: " << 3.1415 << std::ends;
std::cout << buffer.str() << std::endl;
buffer.freeze(false);
buffer.seekp(-1,std::ios::end);
std::cout << buffer.str() << std::endl;
buffer.freeze(false);
buffer.seekp(-1,std::ios::end);
buffer << " or also: " << std::scientific << 3.1415<< std::ends;
str() freezes the char* stream
std::cout << buffer.str() << std::endl;
buffer.freeze(false);
}
str() freezes the char* stream
std::cout << buffer.str() << std::endl;
buffer.freeze(false);
}
C++
Destructor Programs
#include
#include
using
namespace std;
class
marks
{
public:
int
maths;
int
science;
marks()
{
cout<<”Inside
constructor”<
cout<<”C++
object created”<
}
~marks()
{
cout<<”
Inside Destructor”<
cout<<”C++
Object destructed”<
}
};
int
main()
{
marks
m1;
marks
m2;
return
0;
}
Output
Inside
constructor
C++
object created
Inside
constructor
C++
object created
Inside
Destructor
C++
Object destructed
Inside
Destructor
C++
Object destructed
Size
of Data Types
#include
#include
using
namespace std;
int
main()
{
cout<<”
Size of int:”<
cout<<”Size
of long int:”<
cout<<”Size
of float:”<
cout<<”Size
of double:”<
cout<<”Size
of char:”<
return
0;
}
Output
Size of
int : 4
Size of
long int : 4
Size of
float : 4
Size of
double : 8
Size of
char : 1
No comments:
Post a Comment