Note: Here are some of my notes, problems, and solutions in the process of learning c. If you have time to write them down, it may be trivial and not systematic, but I think some people may encounter the same problem and find a solution everywhere. If you can help me, I will be very happy.
I will only talk about one problem in each article, and try to clear the cause and solution as much as possible. Due to the limited level, I cannot guarantee that everything is correct. If there are any mistakes, thank you for your criticism.
The Console. Read () function reads one character and returns the int type;
The Console. ReadLine () function reads a line of characters and returns the string type.
The prototype is as follows:
Public static int Read ();
The next character in the input stream. If no more characters are available for reading, the value is minus one (-1 ).
Public: static String ^ ReadLine ()
The next line of Characters in the input stream. If there are no more available lines, it is a null reference (Nothing in Visual Basic ).
The following code cannot be compiled:
String name;
Name = Console. Read ();
Error: error CS0029: The type "int" cannot be converted to "string"
In this way, you can:
String name;
Name = Console. ReadLine ();