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(id, stock, published,
price, type, title, author);
Console.WriteLine("Update Number In Stock");
Console.WriteLine("=======================");
Console.Write("Item ID: ");
Console.Write(id);
Console.WriteLine("Item Type: ");
Console.Write(type);
}
void read_one_record(int id, int stock, int published,
double price, string type, string title, string author)
{
StreamReader myFile = File.OpenText("Inventory.dat");
id = myFile.Read();
stock = myFile.Read();
published = myFile.Read();
stock = myFile.Read();
price = myFile.Read();
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 = 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();
}
}
}
代码意味着打开一个库存文件,拉入信息,将其传递回main,主要我将要求用户更新库存#。然后将该数字传递给它写入的writefunction
。出于某种原因,当我尝试启动以查看它是否有效时(代码不是100 $完成但仍应编译)。它说的是项目.exe缺少并且无法调试的内容。
答案 0 :(得分:1)
您没有获得EXE,因为您的代码
中有错误StreamWriter myFile = File.OpenWrite("Inventory.dat");
FileStream与StreamWriter不同,但您可以使用
创建StreamWriterStreamWriter myFile = new StreamWriter(File.OpenWrite("Inventory.dat"));