using System;
using System.IO;
namespace tampilan_nama_n_nim_filetxt
{
class Program
{
public static void tulis_file(){
Console.WriteLine(" Text File I/O ");
Console.WriteLine(" Menggunakan Array 1 dimensi ");
Console.WriteLine();
Console.Write(" Masukkan Jumlah Mahasiswa = ");
int jumlah = Convert.ToInt32(Console.ReadLine());
string [] dataArray = new string[jumlah];
for(int y=0; y < jumlah ; y++)
{
Console.Write(" Mahasiswa ke " +(y+1).ToString()+" = ");
dataArray[y] = Console.ReadLine();
}
string data = " ";
for(int i=0; i < jumlah ; i++)
{
data += dataArray[i]+" \r\n ";
}
Console.WriteLine();
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 test.txt");
Console.WriteLine(data);
}
public static void Main(string[] args)
{
tulis_file();
baca_file ();
Console.ReadKey(true);
}
}
}
C++ :
#include#include using namespace std; int main() { ifstream input; input.open("text.txt"); cout << " Text File I/O " << endl; cout << " Menggunakan Array 1 dimensi " << endl; cout << " " << endl; int jumlah; cout << " Masukkan Jumlah Mahasiswa = "; cin >> jumlah; string dataArray [jumlah]; for(int y=0; y < jumlah ; y++) { cout << " Nama Mahasiswa ke " << (y+1) << " = "; cin >> dataArray[y]; } cout << " " << endl; string data = " " ; for(int i = 0 ; i < jumlah ; i++) { cout << dataArray[i]<< "\r\n"; } input.close(); ofstream output; output.open("text.txt"); for(int i=0 ; i < jumlah ; i++) { output << dataArray[i]<< "\r\n"; } return 0; }



0 komentar:
Posting Komentar