可能重复:
寻找与 scanf 等效的 C#
我正在尝试将一行代码从 c 转换为 c#
fscanf(fp, "%d %d\n", &x,&y);
c# 中有 fscanf() 的等效函数吗?我如何转换这行代码?
更新: fp 是指向包含这样输入的文本文件的文件指针
0 0
我需要将整数输入分别保存到 x 和 y。
可能重复:
寻找与 scanf 等效的 C#
我正在尝试将一行代码从 c 转换为 c#
fscanf(fp, "%d %d\n", &x,&y);
c# 中有 fscanf() 的等效函数吗?我如何转换这行代码?
更新: fp 是指向包含这样输入的文本文件的文件指针
0 0
我需要将整数输入分别保存到 x 和 y。
var parts = streamReader.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
int x = Int32.Parse(parts[0]);
int y = Int32.Parse(parts[1]);
String.Format("someFormatString", MyFileStreamReader.ReadLine());
查看BinaryReader类。在 C# 中,您将使用 Stream 对象代替 C FILE 指针。像这样的东西应该工作
System.IO.Stream fp = System.IO.File.OpenRead(@"C:\Path\To\My\File.txt");
double x, y;
using (var reader = new System.IO.BinaryReader(fp))
{
x = reader.ReadDouble();
y = reader.ReadDouble();
}