开发者

Like freopen and scanf in c#

There are freopen and scan开发者_如何转开发f functions from c but for c#?


This should do it:

Console.SetIn(File.OpenText("file.txt"));

Source: cyberforum
Could be helpful for people who stumble upon this question in the future.


Filestream and Streamreader.


freopen does not have a direct parallel. You'd have to Close and then re-create a FileStream object to get similar behavior.

scanf and similar type-unsafe functions have been replaced with Parse methods, e.g., int.Parse. Your stdin stream is Console.In. You'll have to do your own delimiting from the input stream into a string, which can then be parsed into an integer.


I doit like this, as you say:

StreamReader objReader = new StreamReader("input.txt");

String readed = "";

while(readed != null){
    readed = objReader.ReadLine();  
    System.out.println(readed);
}

using StreamReader then I can split it with ' ' to take each variable (in c will be scanf("%d%d%d",&v1,&v2,&v3))

thanks


I've just posted a scanf() replacement using C#. You can see and download the code at http://www.blackbeltcoder.com/Articles/strings/a-sscanf-replacement-for-net.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜