File handling in c++ and c# with Compile and Run from Command prompt 38

Опубликовано: 06 Май 2026
на канале: Arif Mahmood
68
1

Learn how to #compile and #run a c plus plus and c sharp code in #command prompt. How to use notepad to write a #program #code. How to do #file handling in command line. How create and run #executable files.

c++ code:
#include <iostream> //for cout
#include <fstream> // for ofstream/ifstream
#include <string> //for << and getline
int main()
{
std::ifstream input_file("test.txt");
std::ofstream output_file("test.txt.out");

std::string line;
for (int line_no = 1; std::getline(input_file, line); ++line_no)
{

std::cout << "LINE " << line_no << ":" << line << std::endl;
output_file << "LINE " << line_no << ":" << line << std::endl;
}
if (input_file)
{
input_file.close();
output_file.close();
}
std::cin.get();
return 0;
}

c# code:
using System;
using System.IO;//to use StreamReader
namespace lec1csharp
{
class Program
{
static void Main(string[] args)
{
StreamReader input_file = new StreamReader("test.txt");
StreamWriter output_file = new StreamWriter("test.txt.out");

string line = "";
for (int line_no = 1; (line = input_file.ReadLine()) != null; ++line_no)
{
Console.WriteLine("LINE {0} :{1}", line_no, line);
output_file.WriteLine("LINE {0} :{1}", line_no, line);
}
if (input_file != null)
{
input_file.Close();
output_file.Close();
}

Console.ReadLine();
}
}
}

#cplusplus #csharp #tutorial

How to Run C# .Net Program in Command Prompt
C# programming with command prompt console application
Compiling C# in the Command Prompt