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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

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

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

c ++查找字符串

Program 1:

程序1:

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

Output:

輸出:

10 20

Explanation:

說明:

In the above program, we created class Sample and two objects A and B using before semicolon at the end of the class.

在上面的程序中,我們創建了Sample類,并在類末尾使用分號前的兩個對象A和B。

In the main() function, we call set() and print() function, then it will print "10 20" on the console screen.

在main()函數中,我們調用set()和print()函數,然后它將在控制臺屏幕上打印“ 10 20”

Program 2:

程式2:

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

Output:

輸出:

main.cpp:4:1: error: ‘const’ can only be specified for objects and functionsconst class Sample {^~~~~

Explanation:

說明:

The above program will generate an error because we cannot use the const keyword with class declaration. The const keyword can be used with data members and member functions of the class.

上面的程序將產生錯誤,因為我們不能在類聲明中使用const關鍵字 。 const關鍵字可與類的數據成員和成員函數一起使用。

Program 3:

程式3:

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

Output:

輸出:

main.cpp:12:13: error: found ‘:’ in nested-name-specifier, expected ‘::’void Sample : set(int x)^ main.cpp:17:13: error: found ‘:’ in nested-name-specifier, expected ‘::’void Sample : print()^

Explanation:

說明:

The above program will generate errors because in the above program we declare member function inside the class and defined outside the class. But we use the colon operator instead of scope resolution operator ("::" ).

上面的程序將產生錯誤,因為在上面的程序中,我們在類內部聲明成員函數 ,并在類外部定義成員函數 。 但是我們使用冒號運算符而不是范圍解析運算符(“ ::”) 。

Recommended posts

推薦的帖子

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

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

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

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

  • 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-3.aspx

c ++查找字符串

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

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

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