Answer the question
In order to leave comments, you need to log in
How to rewrite integer elements from one file to another in c++?
There is a file:
cin >> n;
ofstream out;
out.open(“dsa.bat”, ios::binary);
for (int i=0; i < n; i++) {
a = rand() % 25 + (-10);
out.write((char*) & a, sizeof(int));
ofstream out1(“dsa1.bat”, ios::binary);
ofstream out2(“dsa2.bat”, ios:binary);
if (a > 0 && a = 0) {
out1 << a;
}
else {
out2 << a;
}
}
out.close();
out1.close();
out2.close();
if (a > o) {s = a}
. In this case, only the first element from the end (if it is positive) is put in s. While doesn't exit either. I want to sort it out.
Answer the question
In order to leave comments, you need to log in
Hello.
My solution to the problem using the string class:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream Q("First.txt");
ofstream Z("Second.txt");
string temporary;
while (Q >> temporary) // извлекаем число из первого
{
Z << temporary << " "; // помещаем число во второй файл
}
Q.close(); Z.close(); return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question