Skip to content

Instantly share code, notes, and snippets.

@lecuseasar
Last active June 12, 2021 16:12
Show Gist options
  • Save lecuseasar/23dd72afd85071d41e230cb4d3ebcc64 to your computer and use it in GitHub Desktop.
Save lecuseasar/23dd72afd85071d41e230cb4d3ebcc64 to your computer and use it in GitHub Desktop.
I/O Redirection
#include <iostream>
#include <fstream>
#include <string>
void readFile(){
std::fstream file;
file.open(R"(C:\Users\emrep\Documents\everyday\cpp\one_day\a.txt)", std::ios::out);
std::string line;
//std::cout << line << std::endl;
std::streambuf* stream_buffer_cout = std::cout.rdbuf();
std::streambuf* stream_buffer_cin = std::cin.rdbuf();
std::streambuf* stream_buffer_file = file.rdbuf();
std::cout.rdbuf(stream_buffer_file);
std::cout<< "bu satir dosyaya yazildi" << std::endl;
std::cout.rdbuf(stream_buffer_cout);
std::cout<< "bu satir ekrana yazildi" << std::endl;
file.close();
}
int main(){
readFile();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment