473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

restore the flags

2
Hi,

I have this declaration:

class A
{
public:

A(std::ostream &s) : a(s.precision()),
b(s.width()),
c(s.flags()) {};
~A() {};
A(A const &);
A &operator=(A const &);
private:
std::streamsize a, b;
std::ios_base::fmtflags c;
};

int main() {


std::cout << std::hex;
std::cout << "hexa = " << 123 << std::endl;
std::cout << "hexa = " << 123 << std::endl;
{
A::A ss(std::cout);
std::cout << std::dec << "decimal = " << 123 << std::endl;.
std::cout << "decimal = " << 123 << std::endl;
}
std::cout << "hexa = " << 123 << std::endl;

}

I would like to go out of scope and the previous state of std::cout should be restored.

I guess I should do something in the destructor. Any help?

Thanks in advance.
Oct 13 '06 #1
1 1695
arne
315 Expert 100+
Hi,

I have this declaration:

class A
{
public:

A(std::ostream &s) : a(s.precision()),
b(s.width()),
c(s.flags()) {};
~A() {};
A(A const &);
A &operator=(A const &);
private:
std::streamsize a, b;
std::ios_base::fmtflags c;
};

int main() {


std::cout << std::hex;
std::cout << "hexa = " << 123 << std::endl;
std::cout << "hexa = " << 123 << std::endl;
{
A::A ss(std::cout);
std::cout << std::dec << "decimal = " << 123 << std::endl;.
std::cout << "decimal = " << 123 << std::endl;
}
std::cout << "hexa = " << 123 << std::endl;

}

I would like to go out of scope and the previous state of std::cout should be restored.

I guess I should do something in the destructor. Any help?

Thanks in advance.

You may try the following. Seems to work ...

class A
{
public:

A(std::ostream &s) : a(s.precision()),
b(s.width()),
c(s.flags()),
sp(&s){}; // added
~A() { sp->flags(c); };
A(A const &);
A &operator=(A const &);
private:
std::streamsize a, b;
std::ios_base::fmtflags c;
std::ostream *sp; // added
};
Oct 13 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: xo55ox | last post by:
Hi, I have been trying to set up an automated restore process from prod to backup server. First, I schedule the full database backup nightly, transfer the backup file and restore it to the...
13
by: EggsAckley | last post by:
Hi: I have a file that I have been told is a SQL Server backup from a server somewhere. The file is about 200MB in size I am trying to create the database on my local server using RESTORE. I...
5
by: mikkel | last post by:
Hello, Im working on a project where I have to bring at production database in house for regression testing. The people who hosts the database (db2 version 7) has made a backup of the base...
13
by: Andy K | last post by:
Hi , I'm wondering what's going on with a restore I'm trying to do . My DB2 version is a 7.2 on a Linux RH ES 2.1 . I've copy a recent backup that was on NAS for a test on my machine . I...
4
by: africantract | last post by:
Hi There, We have an issue on our db2 restores. We do database dumps every night, and restore them to development servers every morning. This works fine with no errors. However if we backup those...
5
by: abelbfilho | last post by:
I have a backup image with name DADOSADV.0.DB2.NODE0000.CATN0000.20060812230006.001 and I want to restore it on Windows (in another server). In Windows Server I created this folder structure:...
0
by: eyal | last post by:
Hello, I use the SHFileOperation API call with FO_DELETE and FOF_ALLOWUNDO flags to send a file to the recycle bin(VB.NET). In some cases I may need to restore a specific file. I suppose this...
1
by: Alexander Korsunsky | last post by:
Hi! Is it possible to extract the mode flags of a stream (FILE* stream or fstream - object), without looking at how the stream was opened? What I mean by mode flags is wether the stream is opened...
0
by: mitrofun63 | last post by:
Hello. On my production site i have DB2 9.1.2 database configured for archiving logs and making backup through TSM Data Protection for DB2 UDB The LOGARCHMETH1 parameter is set to ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.