Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void write_textfile() {
- const char* filename = "C:/goncharov/testfile.txt";
- const char* content = "Hello ";
- FILE* pfile = nullptr;
- //int number = 7777;
- fopen_s(&pfile, filename, "w");
- if (pfile != nullptr) {
- for(int number = 0; number < 10; number++)
- fprintf(pfile, "%s %d \n", content, number);
- fclose(pfile);
- cout << "Job done";
- }
- else {
- cout << "File dose not opened.";
- }
- }
- void read_textfile() {
- const char* filename = "C:/goncharov/testfile.txt";
- FILE* pfile = nullptr;
- fopen_s(&pfile, filename, "r");
- char content[1024];
- if (pfile != nullptr) {
- while(fgets(content, 1024, pfile))
- cout << content;
- /*
- while (!feof(pfile)) {
- fscanf_s(pfile, "%s\n", content, 1024);
- cout << content << " ";
- }
- */
- fclose(pfile);
- cout << "\nReady\n";
- }
- else {
- cout << "File dose not opened.\n";
- }
- }
- int main() {
- setlocale(LC_ALL, "ru_RU.UTF-8");
- //write_textfile();
- read_textfile();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement