我们可以在构造函数中使用printf / cout / consol.writeline,它会在输出屏幕上打印吗?在任何语言C,C ++,C# [英] Can we use printf/cout/consol.writeline in constructor , will it printed on output screen? In any language C, C++, C#
本文介绍了我们可以在构造函数中使用printf / cout / consol.writeline,它会在输出屏幕上打印吗?在任何语言C,C ++,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以在构造函数中使用printf / cout / console.writeline,它会在输出屏幕上打印吗?在任何语言c,c ++,c#创建对象时?
我尝试过:
我们可以在构造函数中使用printf / cout / consol.writeline,它会在输出屏幕上打印吗?在任何语言c,c ++,c#
Can we use printf/cout/console.writeline in constructor , will it printed on output screen? in any language c,c++,c# when object is created ?
What I have tried:
Can we use printf/cout/consol.writeline in constructor , will it printed on output screen? in any language c,c++,c#
推荐答案
这很困惑,因为C没有构造函数,所以printf
是无关紧要的。
C ++和C#都有对象构造函数,你可以愉快地在构造函数中用任何一种语言调用相应的文本输出方法:cout
对于C ++,和C#的Console.WriteLine
或Debug.WriteLine
。
请注意,除非您正在开发基于控制台的应用程序,否则您没有文本显示,用户可以自动查看 - 因此这些方法在现有应用程序中的使用非常有限,其中UI元素如此因为文本框和标签通常用于与用户通信。
That's confused, because C doesn't have constructors, soprintf
is irrelevant.
C++ and C# both have object constructors, and you can happily call the appropriate text output methods in constructors with either language:cout
for C++, andConsole.WriteLine
orDebug.WriteLine
for C#.
Do note that unless you are developing a Console based application, you don;t have a "text display" that the user can automatically see - so these methods are of very limited use in modern applications where UI elements such as text boxes and labels are more normally used to communicate with the user.
这篇关于我们可以在构造函数中使用printf / cout / consol.writeline,它会在输出屏幕上打印吗?在任何语言C,C ++,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文