c++指针引用导出文件
生活随笔
收集整理的這篇文章主要介紹了
c++指针引用导出文件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
std::cout的文件輸出
c++中想要用std::cout這種控制臺輸出內(nèi)容操作,輸出到指定文件
.h文件(a.h)
#ifndef _A_H #define _A_H #include <fstream> #include <iostream> #include <string>class A { private:std::ofstream* outstream = NULL; public:A();~A();A& operator<<(const std::string& std);A& operator<<(const int value);A& operator<<(std::ostream& (*os)(std::ostream&)); };#endif.cpp文件(a.cpp)
#include "a.h" #include <iostream> #include <string>#define FILE_NAME "a.log"A::A() {outstream = new std::ofstream(FILE_NAME); }A::~A() {outstream->close();delete outstream; }A& A::operator<<(const std::string& str) {(*outstream) << str;return (*this); }A& A::operator<<(const int value) {(*outstream) << value;return (*this); }A& A::operator<<(std::ostream& (*os)(std::ostream&)) {(*outstream) << os;return (*this); }main使用
#include <iostream> #include <string.h> #include "a.h" A* a= new A(); int main(int argc, char* argv[]) { (*decompileLogger) << "\t(" << 12 << ")" << std::endl; }最后博主簡簡單單使用工具
總結(jié)
以上是生活随笔為你收集整理的c++指针引用导出文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 熊猫TV是什么?
- 下一篇: 怎么关闭无线局域网助理也就是俗称的WIF