CSharp :
using System;
using System.IO;
namespace nama_nim_filetxt
{
class Program
{
public static void tulis_file()
{
Console.WriteLine(" Text File I/O ");
Console.WriteLine(" Menggunakan Array 2 Dimensi ");
Console.WriteLine();
Console.Write("Masukkan Jumlah Mahasiswa : ");
int x = Convert.ToInt32(Console.ReadLine());
string [,] dataArray1 = new string[x,1];
string [,] dataArray2 = new string[x,1];
for(int i=0; i < x ; i++)
{
for(int j=0; j < 1; j++)
{
Console.Write("NIM Mahasiswa ke – " + (i+1).ToString() + " = ");
dataArray1[i,j]=Console.ReadLine();
Console.Write("Nama Mahasiswa ke – " + (i+1).ToString()+" = ");
dataArray2[i,j]=Console.ReadLine();
}
}
string data="";
for(int i=0 ; i < x ; i++)
{
for(int j=0; j < 1 ; j++)
{
data +="NIM = " +dataArray1[i,j]+" # "+"Nama = "+dataArray2[i,j]+"\r\n";
}
}
StreamWriter sw = new StreamWriter("test.txt");
sw.WriteLine(data);
sw.Close();
Console.WriteLine("Sukses menuliskan data ke file test.txt");
}
public static void baca_file()
{
StreamReader sr = new StreamReader("test.txt");
string data = sr.ReadToEnd();
sr.Close();
Console.WriteLine("Baca file.txt");
Console.WriteLine(data);
}
public static void Main(string[] args)
{
tulis_file();
baca_file();
Console.ReadKey(true);
}
}
}
C++ :