Created
August 3, 2016 11:24
-
-
Save KentaYamada/582eda89209cb9d6f5638fcb52c884a1 to your computer and use it in GitHub Desktop.
ofsstreamのサンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <fstream> | |
int main() | |
{ | |
std::string data = "hoge, piyo, fuga"; | |
std::ofstream ofs; | |
ofs.open("./test.txt", std::ios::out | std::ios::trunc); | |
if(!ofs.is_open()) { | |
std::cout << "file open failed." << std::endl; | |
return -1; | |
} | |
for(int i = 0; i < 1000; i++) { | |
ofs << "No." << i << " " << data << std::endl; | |
if(ofs.fail()) { | |
std::cout << "write error." << std::endl; | |
ofs.close(); | |
return -1; | |
} | |
} | |
ofs.close(); | |
std::cout << "test.txt created." << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment