RUVIDEO
Поделитесь видео 🙏

Split Code to Multiple (source/header/class) files in c++ and c# on Linux(bash) 19

Learn how to run a #program in #Linux/#Unix. How to take contents of an input file, process and store those into an output file. How to #compile and #run a c plus plus and c sharp #project with multiple files. How to #divide/#split code into #multiple #files on #bash.

c++ code:
//Source.cpp is a source file
#include <iostream> //for cout
#include <fstream > // for ofstream/ifstream
#include <string > //for << and getline
#include <list > //for lists
#include"Header.h"

int main(int argc, char *argv[])
{
std::string file = "test.txt";

std::list<file_element >elements;
elements.clear();

pullout_contents(file, elements);

show_contents(std::cout, elements);

pushin_contents(file + ".out", elements);

std::cin.get();
return 0;
}



//Header.h is a header file
#pragma once
#ifndef GUARD_TOKENS_H
#define GUARD_TOKENS_H

class file_element
{
public:
std::string line;
};

void pullout_contents(std::string in_file, std::list<file_element >&elements);
void show_contents(std::ostream &out, const std::list<file_element >&elements);
void pushin_contents(std::string out_file, const std::list<file_element >&elements);

#endif



//Source1.cpp is another source file
#include <iostream > //for cout
#include <fstream > // for ofstream/ifstream
#include <string > //for << and getline
#include<list> //for lists
#include"Header.h"

void pullout_contents(std::string in_file, std::list<file_element >&elements)
{
std::ifstream input_file(in_file.c_str());

elements.clear();
std::string line;
for (int line_no = 1; std::getline(input_file, line); ++line_no)
{
file_element element;
element.line = line;
elements.push_back(element);
}
input_file.close();
}
void show_contents(std::ostream &out, const std::list<file_element >&elements)
{
std::list< file_element:>:const_iterator iter = elements.begin();
for (; iter != elements.end(); ++iter)
{
out << (*iter).line << std::endl;
}
}

void pushin_contents(std::string out_file, const std::list< file_element >&elements)
{
std::ofstream output_file(out_file.c_str());
show_contents(output_file, elements);// using polymorphism
output_file.close();
}



c# code:
//Program.cs is a class file
using System;
using System.Collections.Generic;//for string
using System.IO;//to use StreamReader

namespace lec2csharp
{
class Program
{
static void Main(string[] args)
{
StreamReader input_file = null;
StreamWriter output_file = null;

string file = "test.txt";

List< File_element >elements = new List< File_element >();
elements.Clear();

Header.Pullout_contents(file, elements);

Header.Show_contents(output_file, elements);

Header.Pushin_contents(file + ".out", elements);

if (input_file != null)
{
input_file.Close();
output_file.Close();
}
Console.ReadLine();
}
}
}



//Class1.cs is another class file
using System;
using System.Collections.Generic;
using System.IO;//to use StreamReader

namespace lec2csharp
{
class File_element
{
internal string line;
};

class Header
{
internal static void Pullout_contents(string in_file, List< File_element >elements)
{
StreamReader input_file = new StreamReader(in_file.ToString());
elements.Clear();
string line = "";
for (int line_no = 1; (line = input_file.ReadLine()) != null; ++line_no)
{
File_element element = new File_element();
element.line = line;
elements.Add(element);
}
}

internal static void Show_contents(StreamWriter Out, List<File_element> elements)
{
foreach (File_element iter in elements)
{
Console.WriteLine(iter.line);
}
}

internal static void Pushin_contents(string out_file, List< File_element >elements)
{
StreamWriter output_file = new StreamWriter(out_file.ToString());
output_file.AutoFlush = true;
Console.SetOut(output_file);
Show_contents(output_file, elements);// using polymorphism
}
}
}

#cplusplus #csharp #tutorial

C# on Linux

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Split Code to Multiple (source/header/class) files in c++ and c# on Linux(bash) 19», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.