Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- std::string myEof(std::ifstream &stream) {
- std::string ans;
- if (!stream) {
- std::cout << "File not found\n";
- } else {
- char ch;
- while (!stream.eof()) {
- stream.get(ch);
- ans.push_back(ch);
- if (!stream.eof()) std::cout << ch; //eof - end of file, returns bool val
- }
- stream.close();
- }
- return ans;
- }
- void put(char *name, std::string data) {
- std::ofstream out(name, std::ios::out | std::ios::binary);
- if (!out) std::cout << "File not found\n";
- else {
- int i = 0;
- while (i < data.size()) {
- out.put(data[i]);
- i++;
- }
- }
- out.close();
- }
- int main() {
- // std::ofstream out1("Word.bin", std::ios::out | std::ios::binary);
- // put("Word.bin",
- // "Tron\nShusha\nZamanov\nMoquda\nboss\nmain\nScooby\nvoid\nShamakhi\nKiev\nBaku\nLeon\nstep\nroot\nSuleyman\nBaku\nMaide\n");
- // std::ifstream in("Word.bin", std::ios::in | std::ios::binary);
- // std::string get = myEof(in);
- // std::cout<<'\n';
- // for(int i = 0;i<get.size();i++){
- // get[i] = ~get[i];
- // }
- // std::ifstream out("Word.bin", std::ios::out | std::ios::binary);
- // put("Word.bin", get);
- std::ifstream in2("Word.bin", std::ios::in | std::ios::binary);
- std::string get2 = myEof(in2);
- std::cout << '\n';
- for (int i = 0; i < get2.size(); i++) {
- std::cout << (char) ~get2[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement