Поток ввода/вывода C++C++

Программы на C++. Форум разработчиков
Ответить
Гость
 Поток ввода/вывода C++

Сообщение Гость »


I have a problem with I/O streams in c++. I have to write a program which read data from file and writes it into another file. Command in CMD should be like: "program < file1 > file2". The names of the files should be provided by the user (could be random).I've written a code but it's not correct. I don't know how to redirect stream to file using command "> file2". What I can change in my code to make it work? Can somebody help me?

Код: Выделить всё

#include 
#include 
#include 

int main() {
std::string input_line;
while (std::getline(std::cin, input_line)) {
std::ofstream output_file("file2.txt", std::ios::app);
if (!output_file.is_open()) {
std::cerr 

Источник: [url]https://stackoverflow.com/questions/78133486/c-input-output-stream[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»