当前位置: 首页>>代码示例>>C++>>正文


C++ ofstream::rdbuf方法代码示例

本文整理汇总了C++中std::ofstream::rdbuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::rdbuf方法的具体用法?C++ ofstream::rdbuf怎么用?C++ ofstream::rdbuf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ofstream的用法示例。


在下文中一共展示了ofstream::rdbuf方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cout

	StdHandleSaver(const char* in, const char* out) :
		cin(std::cin.rdbuf()), cout(std::cout.rdbuf()), cerr(std::cerr.rdbuf()), clog(std::clog.rdbuf()),
		csh(in, out),
//	NOTE: Using undocumented constructor accepting FILE*
//	      Only constructor accepts FILE* and swap is specified since C++11, so we need to use constructor
		ifs(stdin), ofs(stdout)
	{
		std::cin.rdbuf(ifs.rdbuf());
		std::cout.rdbuf(ofs.rdbuf());
		std::cerr.rdbuf(ofs.rdbuf());
		std::clog.rdbuf(ofs.rdbuf());
	}
开发者ID:yak1ex,项目名称:ccf,代码行数:12,代码来源:sandbox.cpp

示例2: redirect_cout

bool redirect_cout (const std::string& fn)
{
	static std::ofstream alt_cout;
	alt_cout.open (fn.c_str(), std::ios::out | std::ios::binary);
	if (alt_cout.fail() ) return false;
	std::cout.rdbuf (alt_cout.rdbuf() );
	return true;
}
开发者ID:frankwz,项目名称:codecrypt,代码行数:8,代码来源:iohelpers.cpp

示例3: UnityPluginLoad

// --------------------------------------------------------------------------
// UnitySetInterfaces
void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces *unityInterfaces) {
#if defined(ENABLE_LOGGING) && defined(ENABLE_LOGFILE)
    s_debugLogFile.open("RenderPluginLog.txt");

    // Capture std::cout and std::cerr from RenderManager.
    if (s_debugLogFile) {
        s_oldCout = std::cout.rdbuf();
        std::cout.rdbuf(s_debugLogFile.rdbuf());

        s_oldCerr = std::cerr.rdbuf();
        std::cerr.rdbuf(s_debugLogFile.rdbuf());
    }
#endif // defined(ENABLE_LOGGING) && defined(ENABLE_LOGFILE)
    s_UnityInterfaces = unityInterfaces;
    s_Graphics = s_UnityInterfaces->Get<IUnityGraphics>();
    s_Graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);

    // Run OnGraphicsDeviceEvent(initialize) manually on plugin load
    OnGraphicsDeviceEvent(kUnityGfxDeviceEventInitialize);
}
开发者ID:OSVR,项目名称:OSVR-Unity-Rendering,代码行数:22,代码来源:OsvrRenderingPlugin.cpp

示例4: openStreamInto

 void openStreamInto( Ptr<Config> const& config, std::ofstream& ofs ) {
     // Open output file, if specified
     if( !config->getFilename().empty() ) {
         ofs.open( config->getFilename().c_str() );
         if( ofs.fail() ) {
             std::ostringstream oss;
             oss << "Unable to open file: '" << config->getFilename() << "'";
             throw std::domain_error( oss.str() );
         }
         config->setStreamBuf( ofs.rdbuf() );
     }
 }
开发者ID:JorySchossau,项目名称:Empirical,代码行数:12,代码来源:catch_session.hpp

示例5: setup_files

bool setup_files() {

    configOptions["login_logfile"] = configOptions["logdir"] + configOptions["starttime"] + std::string(".log");
    configOptions["kill_logfile"] = configOptions["logdir"] + configOptions["starttime"] + std::string(".kills");
    configOptions["cout_logfile"] =  configOptions["coutdir"] + configOptions["starttime"] + std::string(".out");
    configOptions["cerr_logfile"] =  configOptions["coutdir"] + configOptions["starttime"] + std::string(".err");

    std::cout << "redirecting all further output to file: " << configOptions["cout_logfile"] << std::endl;
    std::cout << "redirecting error output to file: " << configOptions["cerr_logfile"] << std::endl;

    // open files for redirectings stdout/stderr
    coutfile.open(configOptions["cout_logfile"].c_str(), std::ios::out | std::ios::trunc);
    cerrfile.open(configOptions["cerr_logfile"].c_str(), std::ios::out | std::ios::trunc);

    // check if files are ok
    if (!coutfile.good()) {
        std::cerr << "Could not open stdout log file for writing: " << configOptions["cout_logfile"] << std::endl;
        return false;
    }

    if (!cerrfile.good()) {
        std::cerr << "Could not open stderr log file for writing: " << configOptions["cerr_logfile"] << std::endl;
        return false;
    }

    // redirect stdout/stderr
    std::cout.rdbuf(coutfile.rdbuf());
    std::cerr.rdbuf(cerrfile.rdbuf());

    kill_log.open(configOptions["kill_logfile"].c_str());

    if (!kill_log.good()) {
        std::cerr << "Could not open kill log file for writing: " << configOptions["kill_logfile"] << std::endl;
        return false;
    }

    return true;

}
开发者ID:shcalm,项目名称:Illarion-Server,代码行数:39,代码来源:main_help.cpp

示例6:

IO::IO(const Settings &s, MPI_Comm comm)
{
    m_outputfilename = s.outputfile;

    if (m_outputfilename == "cout")
    {
        buf = std::cout.rdbuf();
    }
    else
    {
        int rank;
        MPI_Comm_rank(comm, &rank);
        std::string rs = std::to_string(rank);
        of.open(m_outputfilename + rs + ".txt");
        buf = of.rdbuf();
    }
}
开发者ID:Bella42,项目名称:ADIOS2,代码行数:17,代码来源:IO_ascii.cpp

示例7: setTrace

void setTrace(Rose_STL_Container<string> &cmdLineArgs)
{
    if ((CommandlineProcessing::isOption (cmdLineArgs,"--verbose","",true))
            || (CommandlineProcessing::isOption (cmdLineArgs,"-v","",true)) )
    {
        tracePtr = &std::cout;
        verbose = true;
    }
    else
    {
        static std::ofstream null("/dev/null");
        static std::ostream nullTrace(null.rdbuf());
        nullPtr = &null;
        tracePtr = &nullTrace;
        verbose = false;
    }
}
开发者ID:alexjohn1362,项目名称:rose,代码行数:17,代码来源:Main.cpp

示例8: redirectOut

		void mpi_spread::redirectOut()
		{
			#ifdef HAVE_MPI
		  
			if (rank != 0)
			{
				std::streambuf *psbuf;
				dev_null.open("/dev/null");

				backup_out = std::cout.rdbuf();     // back up cout's streambuf
				backup_err = std::cout.rdbuf();     // back up cout's streambuf

				psbuf = dev_null.rdbuf();   // get file's streambuf
				std::cout.rdbuf(psbuf);         // assign streambuf to cout
				std::cerr.rdbuf(psbuf);         // assign streambuf to cout
				
			}
			
			#endif
		}
开发者ID:geeklhem,项目名称:spopdyn,代码行数:20,代码来源:mpi_spread.cpp

示例9: activateTraceLog

bool TraceLog::activateTraceLog( bool isActive ){
	if ( isActive ){
        try{

            std::string traceFileName = "traceLog"+getTime()+".log";
            out.open(traceFileName.c_str() );
            std::streambuf *countbuf = std::cout.rdbuf();
            std::cout.rdbuf ( out.rdbuf() ) ;
            AddTimeStamp ats( cout );

            std::cout<<"buffer pointed\n";
                }
		catch ( std::exception &e ){
			std::cerr<<"exception caight\n";
			return false;
		}
		return true;

	}
	else{ //have to do some logic thus std::cout<<"print data\n" won;t print any thing to standard output.
    }
}
开发者ID:Afelio,项目名称:DatabaseStub,代码行数:22,代码来源:loghandle_old.cpp

示例10: dfile

/*
	Random stuff
*/
u16 g_selected_material = 0;

/*
	Debug streams
	- use these to disable or enable outputs of parts of the program
*/

std::ofstream dfile("debug.txt");
//std::ofstream dfile2("debug2.txt");

// Connection
//std::ostream dout_con(std::cout.rdbuf());
std::ostream dout_con(dfile.rdbuf());

// Server
//std::ostream dout_server(std::cout.rdbuf());
std::ostream dout_server(dfile.rdbuf());

// Client
//std::ostream dout_client(std::cout.rdbuf());
std::ostream dout_client(dfile.rdbuf());

/*
	TimeTaker
*/

class TimeTaker
{
开发者ID:EUGD,项目名称:minetest_nmpr,代码行数:31,代码来源:main.cpp

示例11: main

int main()
{
    char buffer[64];

    //logStream.rdbuf()->pubsetbuf(buffer, sizeof(buffer));
    logStream.rdbuf()->pubsetbuf(nullptr, 0);
    logStream.open("log.txt");
    //try
    {

        ny::logLogger().stream = &logStream;
        ny::warningLogger().stream = &logStream;
        ny::errorLogger().stream = &logStream;

        ny::sendLog("Started Iro Desktop");

        iro::Compositor myCompositor;
        iro::Seat mySeat(myCompositor);
        iro::ForkHandler myForkHandler(myCompositor);

        std::unique_ptr<iro::DBusHandler> myDBusHandler = nullptr;
        std::unique_ptr<iro::LogindHandler> myLogindHandler = nullptr;
        std::unique_ptr<iro::DeviceHandler> myDeviceHandler = nullptr;
        std::unique_ptr<iro::Backend> myBackend = nullptr;
        std::unique_ptr<iro::TerminalHandler> myTerminalHandler = nullptr;
        std::unique_ptr<iro::UDevHandler> myUDevHandler = nullptr;
        std::unique_ptr<iro::InputHandler> myInputHandler = nullptr;

        if(iro::X11Backend::available())
        {
            iro::X11Backend* xbcknd = new iro::X11Backend(myCompositor, mySeat);
            myBackend.reset(xbcknd);
            xbcknd->createOutput();
        }
        else
        {
            myDBusHandler.reset(new iro::DBusHandler(myCompositor));
            myLogindHandler.reset(new iro::LogindHandler(*myDBusHandler));
            myDeviceHandler.reset(new iro::DeviceHandler(*myDBusHandler, *myLogindHandler));
            myTerminalHandler.reset(new iro::TerminalHandler(myCompositor));
            myBackend.reset(new iro::KmsBackend(myCompositor, *myDeviceHandler));
            myUDevHandler.reset(new iro::UDevHandler(myCompositor));
            myInputHandler.reset(new iro::InputHandler(myCompositor, mySeat,
                                 *myUDevHandler, *myDeviceHandler));

            static_cast<iro::KmsBackend*>(myBackend.get())->setCallbacks(*myTerminalHandler);
            myLogindHandler->onActive([&](bool b)
            {
                ny::sendLog("active: ", b);
                if(b)
                {
                    myInputHandler->resume();
                    //myTerminalHandler->activate(myTerminalHandler->number());
                    //myTerminalHandler->waitActive(myTerminalHandler->number());
                }
                else
                {
                    myInputHandler->suspend();
                }
            });

            std::cout << (int)mySeat.keyboard()->modifiers() << "\n";
            std::cout << (int)(iro::Keyboard::Modifier::ctrl | iro::Keyboard::Modifier::alt) << "\n";

            if(mySeat.keyboard())
            {
                mySeat.keyboard()->onKey([&](unsigned int key, bool pressed)
                {
                    if(!pressed) return;

                    if(mySeat.keyboard()->modifiers() !=
                            (iro::Keyboard::Modifier::ctrl | iro::Keyboard::Modifier::alt))
                        return;

                    if(key == KEY_Q)
                    {
                        idleSwitchSource = wl_event_loop_add_idle(&myCompositor.wlEventLoop(),
                                           idleSwitch, myTerminalHandler.get());
                        vtSwitchTo = myTerminalHandler->number() - 1;
                    }
                    else if(key == KEY_E)
                    {
                        idleSwitchSource = wl_event_loop_add_idle(&myCompositor.wlEventLoop(),
                                           idleSwitch, myTerminalHandler.get());
                        vtSwitchTo = myTerminalHandler->number() + 1;
                    }
                });
            }
        }

        if(mySeat.keyboard())
        {

            mySeat.keyboard()->onKey([&](unsigned int key, bool pressed)
            {
                if(mySeat.keyboard()->modifiers() != iro::Keyboard::Modifier::alt) return;
                if(pressed && key == KEY_T)
                {
                    ny::sendLog("starting weston terminal");
                    myForkHandler.exec("weston-terminal", {"--shell=/bin/bash"});
//.........这里部分代码省略.........
开发者ID:nyorain,项目名称:iro,代码行数:101,代码来源:main.cpp

示例12:

 RAIIcout_redirect(std::ofstream& os): _oldbuf(std::cout.rdbuf())
 {
     std::cout.rdbuf(os.rdbuf());
 }
开发者ID:vsoftco,项目名称:snippets,代码行数:4,代码来源:redirect_cout_file_RAII.cpp


注:本文中的std::ofstream::rdbuf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。