-3
I made 2 attempts, the first one is error, and the second one does not write. could help me?
#include<iostream>
#include<fstream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<cstdlib>
using namespace std;
int main()
{
string linha;
fstream fin ("ex2.txt");
ofstream fout("ex2par.txt");
ofstream fout("ex2impar.txt");
if(fin.is_open())
{
while(getline(fin,linha))
{
int num = atoi(linha.c_str());
if (num%2 == 0)
{
cout << "par " << num << endl;
fout.open("ex2par.txt",ios::app);
}
else
{
cout << "impar " << num << endl;
fout.open("ex2impar.txt",ios::app);
}
}
}
}
/*int main()
{
string linha;
fstream fin("ex2.txt");
ofstream par("ex2par.txt");
ofstream impar("ex2impar.txt");
if(fin.is_open())
{
while(getline(fin,linha))
{
int num = atoi(linha.c_str());
if (num%2 == 0)
{
cout << "par " << num << endl;
par.open("ex2par.txt");
}
else
{
cout << "impar " << num << endl;
impar.open("ex2par.txt");
}
}
}
}*/
But the messages you’re sending all to
cout
. At what point did you really try to write the texts we files?– Woss
I did not understand very well, in case it would not be in the declared ofstream par("ex2par.txt"); and the odd ofstream("ex2impar.txt");, because I tried both with FOUT but gave error, as in the commented part
– Brenner Siqueira