日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c ++查找字符串_C ++类和对象| 查找输出程序| 套装1

發布時間:2025/3/11 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c ++查找字符串_C ++类和对象| 查找输出程序| 套装1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c ++查找字符串

Program 1:

程序1:

#include <iostream> using namespace std;class Sample { privateint A; privateint B;publicvoid init(){A = 10;B = 20;} publicvoid print(){cout << A << " " << B;} };int main() {Sample S;S.init();S.print();return 0; }

Output:

輸出:

main.cpp:6:5: error: expected ‘:’ before ‘int’int A;^~~ main.cpp:8:5: error: expected ‘:’ before ‘int’int B;^~~ main.cpp:11:5: error: expected ‘:’ before ‘void’void init()^~~~ main.cpp:17:5: error: expected ‘:’ before ‘void’void print()^~~~

Explanation:

說明:

The above code will generate errors because in the above program we did not use private and public modifiers properly.

上面的代碼將產生錯誤,因為在上面的程序中我們沒有正確使用private和public修飾符 。

In C++, we need to use the colon ":" operator to specify modifiers block. Here we did not use modifiers for each member individually, here we create blocks like,

在C ++中,我們需要使用冒號“ :”運算符來指定修飾符塊。 在這里,我們沒有為每個成員單獨使用修飾符,在這里,我們創建如下塊:

class ABC { private:int A;int B;public:void fun(); };

Here A and B are private members and fun() is public in ABC class.

這里A和B是私有成員,而fun()在ABC類中是公共的。

Program 2:

程式2:

#include <iostream> using namespace std;class Sample { private:int A;int B;public: private: public:void init(){A = 10;B = 20;}void print(){cout << A << " " << B;} };int main() {Sample S;S.init();S.print();return 0; }

Output:

輸出:

10 20

Explanation:

說明:

In the above program, we created a class Sample. Here we created two private members A and B. After that we used modifiers multiple times, In C++, last used modifiers decide the visibility of members so init() and print() function will be public type.

在上面的程序中,我們創建了Sample類。 在這里,我們創建了兩個私人成員A和B。 之后,我們多次使用修飾符,在C ++中,最后使用的修飾符決定成員的可見性,因此init()和print()函數將成為公共類型。

Now, come to main() function, here we created of the object of Sample class and call init() and print() function then the "10 20" will be printed on the console screen.

現在,進入main()函數,在這里我們創建Sample類的對象,并調用init()和print()函數,然后“ 10 20”將被打印在控制臺屏幕上。

Program 3:

程式3:

#include <iostream> using namespace std;class Sample {int A = 10;int B = 20;public:void print(){cout << A << " " << B;} };int main() {Sample S;S.print();return 0; }

Output:

輸出:

10 20

Explanation:

說明:

In the above program, we created a Sample class that contains two data member A and B, they initialized with 10 and 20 respectively. Here we initial member at the time of declaration. It is also possible in C++.

在上面的程序中,我們創建了一個Sample類,其中包含兩個數據成員A和B ,它們分別用10和20初始化。 在這里,我們是宣布時的初始成員。 在C ++中也是可能的。

Here we did not mention any access modifier. In C++, if we did not any specify any modifier then by default it will be considered as a private type.

這里我們沒有提及任何訪問修飾符。 在C ++中,如果我們未指定任何修飾符,則默認情況下它將被視為私有類型。

In the main() function, we create object S of Sample class and then call print() member function of Sample class, which will print "10 20" on the console screen.

在main()函數,我們創建Sample類的對象S,然后呼叫打印() 成員函數 Sample類的,其將打印“10 20”在控制臺屏幕上。

Recommended posts

推薦的帖子

  • C++ Class and Objects | Find output programs | Set 2

    C ++類和對象| 查找輸出程序| 套裝2

  • C++ Class and Objects | Find output programs | Set 3

    C ++類和對象| 查找輸出程序| 套裝3

  • C++ Class and Objects | Find output programs | Set 4

    C ++類和對象| 查找輸出程序| 套裝4

  • C++ Class and Objects | Find output programs | Set 5

    C ++類和對象| 查找輸出程序| 套裝5

  • C++ Looping | Find output programs | Set 1

    C ++循環| 查找輸出程序| 套裝1

  • C++ Looping | Find output programs | Set 2

    C ++循環| 查找輸出程序| 套裝2

  • C++ Looping | Find output programs | Set 3

    C ++循環| 查找輸出程序| 套裝3

  • C++ Looping | Find output programs | Set 4

    C ++循環| 查找輸出程序| 套裝4

  • C++ Looping | Find output programs | Set 5

    C ++循環| 查找輸出程序| 套裝5

  • C++ Default Argument | Find output programs | Set 1

    C ++默認參數| 查找輸出程序| 套裝1

  • C++ Default Argument | Find output programs | Set 2

    C ++默認參數| 查找輸出程序| 套裝2

  • C++ Arrays | Find output programs | Set 1

    C ++數組| 查找輸出程序| 套裝1

  • C++ Arrays | Find output programs | Set 2

    C ++數組| 查找輸出程序| 套裝2

  • C++ Arrays | Find output programs | Set 3

    C ++數組| 查找輸出程序| 套裝3

  • C++ Arrays | Find output programs | Set 4

    C ++數組| 查找輸出程序| 套裝4

  • C++ Arrays | Find output programs | Set 5

    C ++數組| 查找輸出程序| 套裝5

翻譯自: https://www.includehelp.com/cpp-tutorial/class-and-objects-find-output-programs-set-1.aspx

c ++查找字符串

總結

以上是生活随笔為你收集整理的c ++查找字符串_C ++类和对象| 查找输出程序| 套装1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。