using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace as2
{
class Program
{
static void Main(string[] args)
{
int id = 0, stock = 0, published = 0, newstock = 0;
double price = 0.00;
string type = " ", title = " ", author = " ";
Program inventroy = new Program();
inventroy.read_one_record(ref id, ref stock, ref published, ref price, ref type, ref title, ref author);
Console.WriteLine("Update Number In Stock");
Console.WriteLine("=======================");
Console.Write("Item ID: ");
Console.WriteLine(id);
Console.WriteLine("Item Type: ");
Console.Write(type);
}
void read_one_record(ref int id, ref int stock, ref int published, ref double price, ref string type, ref string title, ref string author)
{
StreamReader myFile = File.OpenText("Inventory.dat");
id = int.Parse(myFile.ReadLine());
stock = int.Parse(myFile.ReadLine());
published= int.Parse(myFile.ReadLine());
stock = int.Parse(myFile.ReadLine());
price = double.Parse(myFile.ReadLine());
type = myFile.ReadLine();
title = myFile.ReadLine();
author = myFile.ReadLine();
myFile.Close();
}
void write_one_record(int id, int newstock, int published, double price, string type, string title, string author)
{
StreamWriter myFile = new StreamWriter(File.OpenWrite("Inventory.dat"));
myFile.WriteLine(id);
myFile.WriteLine(newstock);
myFile.WriteLine(published);
myFile.WriteLine(price);
myFile.WriteLine(type);
myFile.WriteLine(title);
myFile.WriteLine(author);
myFile.Close();
}
}
}
Im trying to read in a full line but ReadLine is string and the first thing im pulling from the file is: 123456
123456
15
2011
69.99
book
Problem_Solving_With_C++
Walter_Savitch (the actual text file doesn't have empty lines inbetween)
then 15 then 2011, which should I use? Read? Will I have to use some kind of loop to figure out when the end of the line is?