Move file open and file close operations outside while loop:
#include<iostream>
#include<fstream>
int main()
{
std::ifstream file( "infile.txt" );
std::string in1, out1;
int blockNumber = 0;
std::ofstream fmatch ("solo_matches.txt",std::ios::out);
while( getline( file, in1 ) )
{
int n = 0;
int i = 0;
while( i <= blockNumber )
{
n = in1.find_first_of("(", n + 1);
i++;
}
out1 = in1.substr( n + 1, ( in1.find_first_of(")", n) - n - 1) );
//fmatch.close(); //you don't need this
//fmatch.open("solo_matches.txt"); //you don't need this
std::cout << out1 << std::endl;
fmatch << out1 << std::endl;
}
fmatch.close();
}
And replace
fmatch << out1;
with
fmatch << out1 << endl;
if you need cout
and fmatch
agreement.