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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

c ++查找字符串_C ++结构| 查找输出程序| 套装1

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

c ++查找字符串

Program 1:

程序1:

#include <iostream> #include <math.h> using namespace std;struct st {int A = NULL;int B = abs(EOF + EOF); } S;int main() {cout << S.A << " " << S.B;return 0; }

Output:

輸出:

0 2

Explanation:

說明:

Here, we created a structure that contains two integer variables. Here, we used NULL, EOF, and abs() function for initialization of structure elements.

在這里,我們創建了一個包含兩個整數變量的結構。 在這里,我們使用NULL , EOF和abs()函數初始化結構元素。

The values of NULL and EOF are 0 and -1 respectively. And the function abs() returns positive value always.

NULL和EOF的值分別為0和-1。 并且函數abs()始終返回正值。

A = NULL; //that is 0 A = 0;B = abs(EOF+EOF);= abs(-1+-1);= abs(-1-1);= abs(-2);= 2;

Then, the final value 0 and 2 will be printed on the console screen.

然后,最終值02將被打印在控制臺屏幕上。

Program 2:

程式2:

#include <iostream> using namespace std;typedef struct{int A = 10;int B = 20; } S;int main() {cout << S.A << " " << S.B;return 0; }

Output:

輸出:

main.cpp: In function ‘int main()’: main.cpp:11:14: error: expected primary-expression before ‘.’ tokencout << S.A << " " << S.B;^ main.cpp:11:28: error: expected primary-expression before ‘.’ tokencout << S.A << " " << S.B;^

Explanation:

說明:

Here, we created a structure using typedef that contains two integer variables A and B. Consider the below statement,

在這里,我們使用typedef 創建了一個結構 , 該結構包含兩個整數變量A和B。 考慮以下語句,

cout <<S.A<<" "<<S.B;

Here, we accessed A using S. but S is not an object or variable of structure, we used typedef it means S is type, so we need to create an object of structure using S like, S ob;

在這里,我們訪問的使用S.但S是不是一個對象或結構的變量,我們使用的typedef這意味著S是類型,所以我們需要創建使用S-狀結構的目的,S OB;

Then, ob.A and ob.B will be the proper way to access A and B.

然后, ob.A和ob.B將是訪問A和B的正確方法。

Program 3:

程式3:

#include <iostream> using namespace std;typedef struct{int A;char* STR; } S;int main() {S ob = { 10, "india" };S* ptr;ptr = &ob;cout << ptr->A << " " << ptr->STR;return 0; }

Output:

輸出:

10 india

Explanation:

說明:

Here, we created a structure with two members A and STR. In the main() function, we created the object that is ob, and? a pointer ptr and then assigned the address of ob to ptr. Accessing the elements using referential operator -> and then printed them on the console screen.

在這里,我們創建了一個具有兩個成員A和STR的結構。 在main()函數中,我們創建了對象ob和一個指針ptr ,然后將ob的地址分配給了ptr。 使用引用運算符->訪問元素,然后將其打印在控制臺屏幕上。

The final output "10 india" will be printed on the console screen.

最終輸出“ 10 india”將打印在控制臺屏幕上。

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

c ++查找字符串

總結

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

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