Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- //ofstream - output stream
- //ifstream - input stream
- //fstream - input/output stream
- int main()
- {
- //std::ofstream outf;
- //outf.open("d:\\file.txt");
- //if ( !outf )
- //{
- // std::cout << "IOERROR: can't create/open file!\n";
- // return 1;
- //}
- //outf << "String #1\n";
- //outf << "String #2\n";
- //outf << "String #3\n";
- ////for (int i{ 0 }; i < 10; ++i)
- ////{
- //// outf << i << '\n';
- ////}
- //outf.close();
- std::ifstream inf;
- inf.open("C:\\Users\\ribchansky_o\\source\\repos\\Study\\Study\\Study.cpp");
- if (!inf)
- {
- std::cout << "IOERROR: can't open file!\n";
- return 1;
- }
- const int strSize{ 300 };
- const int textSize{ 500 };
- char str[strSize];
- int lineNumber{ 0 };
- char* text[textSize]{};
- int strLen{};
- while (!inf.eof())
- {
- inf.getline(str, strSize - 1);
- strLen = strlen(str) + 1;
- text[lineNumber] = new char[strLen];
- strcpy_s(text[lineNumber++], strLen, str);
- //std::cout << str << '\n';
- }
- inf.close();
- std::ofstream outf;
- outf.open("d:\\Programm.cpp");
- if ( !outf )
- {
- std::cout << "IOERROR: can't create/open file!\n";
- return 1;
- }
- for (lineNumber = 0; text[lineNumber]; ++lineNumber)
- {
- std::cout << text[lineNumber] << '\n';
- outf << text[lineNumber] << '\n';
- delete[] text[lineNumber];
- }
- outf.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement