>" and "<<" IO in C #? Is there a C # library that provides "โ†’" and "

C ++ ">>" and "<<" IO in C #?

Is there a C # library that provides "โ†’" and "<lt;" functionality for I / O in C ++? It was really convenient for console applications. It is provided that in C # there are not many console applications, but some of them use them for them.

I know about Console.Read [Line] | Write [Line] and Streams | FileStream | StreamReader | StreamWriter, which is not part of the question.

I do not think that it is specific enough

 int a,b; cin >> a >> b; 

AMAZING !!

 string input = Console.ReadLine(); string[] data = input.split( ' ' ); a = Convert.ToInt32( data[0] ); b = Convert.ToInt32( data[1] ); 

... long enough wind? In addition, there are other reasons why the C # solution is worse. I have to get the whole line or make my own buffer for this. If the im line is working, the IDK says 1000 lines of the bell triangle, I spend so much time reading just one at a time.

EDIT: GAR !!!

OK PROBLEM !!!

Using IntX to make a HUGE number, such as .net 4.0 BigInteger, to create a bell triangle. If you know the triangle of a bell, it very quickly becomes huge. The whole point of this question is that I need to deal with each number individually. If you read a whole line, you can easily get into Gigs of data. This is similar to Pi numbers. For example, 42pow1048576 - 1.6 MB! I donโ€™t have the time and memory to read all the numbers as a single line, and then select the one I want

+4
source share
7 answers

I think I get what you need: a simple, formatted input by default. I think the reason is because TextReader.ReadXXX () is because it is parsing and parsing is complex: for example: should ReadFloat ():

  • ignore leading spaces
  • decimal point required
  • space reserved ( 123abc )
  • handle exponentials (is 12.3a3 analyzed differently at 12.4e5 ?)

Not to mention what ReadString () does? From C ++, you expect "read the next space", but the name doesn't say that.

Now all of them have good reasonable answers, and I agree that C # (or rather BCL) should provide them, but I can, of course, understand why they prefer not to provide fragile, it is almost impossible to use functions directly there in the middle class.

EDIT: For a buffering problem, an ugly solution:

 static class TextReaderEx { static public string ReadWord(this TextReader reader) { int c; // Skip leading whitespace while (-1 != (c = reader.Peek()) && char.IsWhiteSpace((char)c)) reader.Read(); // Read to next whitespace var result = new StringBuilder(); while (-1 != (c = reader.Peek()) && !char.IsWhiteSpace((char)c)) { reader.Read(); result.Append((char)c); } return result.ToString(); } } ... int.Parse(Console.In.ReadWord()) 
+1
source

No, and I would not. C# != C++

You should try to adhere to the language agreement of any language in which you work.

+4
source

Nope. You are stuck with Console.WriteLine . However, you can create a wrapper that offers this functionality.

+1
source

You can use Console.WriteLine, Console.ReadLine. For the purpose. Both are in System NameSpace.

+1
source

You have System.IO.Stream (Reader | Writer) And for the console: Console.Write, Console.Read

+1
source

Not that I knew. If you are interested in chaining outputs, you can use System.Text.StringBuilder . http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(VS.71).aspx

 StringBuilder builder = new StringBuilder(); builder.Append("hello").Append(" world!"); Console.WriteLine(builder.ToString()); 

Perhaps not as pretty as C ++, but as another poster claims, C #! = C ++.

0
source

This is not possible even in C #, no matter how you try:

The first thing to do is to overload the operator a little less messy than in C ++ (debatable, but it certainly makes things a lot easier), and the second point was specifically chosen to exclude the C ++ cin and cout way of working with IO, IIRC.

0
source

Source: https://habr.com/ru/post/1302176/


All Articles