c++里public static void什么意思
时间: 2023-06-05 15:04:59 浏览: 225
public和static是Java中的关键字,用于定义类或方法的访问权限和作用域。其中,public表示公共的,可以被其他类访问;static表示静态的,可以用类名直接调用,而不需要创建对象。而void表示该方法没有返回值。所以,public static void表示一个公共、静态的方法,没有返回值。
相关问题
public static extern int _kbhit(); 和public static void Exit()的区别
`public static extern int _kbhit()` 是 C/C++ 中的一个函数,它在 C# 中是通过 P/Invoke 调用的方式来使用的。这个函数的作用是检查键盘缓冲区中是否有按键输入。如果有,则返回非零值,否则返回零。
`public static void Exit()` 是 C# 中的一个静态方法,其作用是退出当前应用程序。调用这个方法后,应用程序将会立即结束,所有未保存的数据将可能会丢失。
这两个方法的作用完全不同,没有可比性。`_kbhit()` 主要用于检测键盘输入,而 `Exit()` 则是用于应用程序的退出。
c++ static string
在C++中,static string是指一个静态的字符串对象。静态字符串对象在程序的整个生命周期内都存在,并且只有一个实例。它可以在类的静态成员函数中使用,也可以在全局范围内使用。
以下是一个演示静态字符串对象的示例代码:
```cpp
#include <iostream>
#include <string>
class MyClass {
public:
static std::string staticString; // 静态字符串对象
static void printStaticString() {
std::cout << staticString << std::endl;
}
};
std::string MyClass::staticString = "Hello, static string!"; // 初始化静态字符串对象
int main() {
MyClass::printStaticString(); // 输出:Hello, static string!
return 0;
}
```
在上面的示例中,我们定义了一个名为MyClass的类,其中包含一个静态字符串对象staticString。我们在类外初始化了这个静态字符串对象,并在类的静态成员函数printStaticString中打印出了该字符串对象的值。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)