I created file which in which I fill strings with a keyboard and my task is to copy from my first file(F1) to second file(F2) all strings which contain only one word.
#include <iostream>
#include <fstream>
#include <clocale>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
int i,n;
char buff[255];
ofstream fout("F1.txt"); // open file for filling
cout << "Enter number of strings ";
cin >> n;
cin.ignore(4096,'\n');
for(i=0;i<n;++i)
{
cout << "[" << i+1 << "-string]" << ":";
cin.getline(buff,255); // write strings from keyboard
fout << buff << "\n"; // fill the file with all strings
}
fout.close(); /close file
const int len = 30;
int strings = n;
char mass[len][strings]; // creating two-dimensional array as buffer while reading
const char ch = '\n';
ifstream fin("F1.txt"); //open file for reading
if (!fin.is_open())
cout << "File can not be open\n"; //checking for opening
else
{
for(int r = 0; r<strings; r++)
{
fin.getline(mass[r], len-1,ch);
cout << "String " << r+1 << " = "<< mass[r] << endl; // output strings from file(buffer)
}
}
return 0;
}