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
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.3a3analyzed differently at12.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()) 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 ++.
This is not possible even in C #, no matter how you try:
- The left part and the right part of operators are always passed by value; this eliminates the possibility of
cin. - The right-hand side of
<<and>>must be an integer; this excludescout.
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.