C++ - Как сбросить флаги манипулятора потока вывода [дубликат]

Вы хотите использовать Activator.CreateInstance .

Вот пример того, как он работает:

using System;
using System.Runtime.Remoting;

class Program
{
    static void Main()
    {
        ObjectHandle o = Activator.CreateInstance("mscorlib.dll", "System.Int32");

        Int32 i = (Int32)o.Unwrap();
    }
}

17
задан John Carter 3 October 2009 в 12:37
поделиться

2 ответа

Have a look at the Boost.IO_State_Savers, providing RAII-style scope guards for the flags of an iostream.

Example:

#include <boost/io/ios_state.hpp>

{
  boost::io::ios_all_saver guard(cout); // Saves current flags and format

  cout << setw(14) << "  CHARGE/ROOM" << endl;
  cout << setfill('-') << setw(11) << '-' << "  " << setw(15) << '-' << "   " << setw(11) << '-' << endl;
// dtor of guard here restores flags and formats
}

More specialized guards (for only fill, or width, or precision, etc... are also in the library. See the docs for details.

28
ответ дан 30 November 2019 в 10:36
поделиться

You can use the ios::fill() function to set and restore the fill character instead.

http://www.cplusplus.com/reference/iostream/ios/fill/

#include <iostream>
using namespace std;

int main () {
  char prev;

  cout.width (10);
  cout << 40 << endl;

  prev = cout.fill ('x');
  cout.width (10);
  cout << 40 << endl;

  cout.fill(prev);

  return 0;
}
9
ответ дан 30 November 2019 в 10:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: