行业知识
【C++ 测试】
2026-10-30 08:42:17
来源:互联网转载
C++ 测试
- 一、二维数组
- 二、私有成员
- 三、function用法
- 四、类里面创建另一个类
- 五、lambda
- �index.php/tags-41973.html" >�、Map动态申请
一、二维数组
#include #include#include //SetConsoleOutputCP ( CP_UTF8 ) ; using namespace std;void test1(){map m;m[0]["sch"] = 1.1;m[1]["hsd"] = 2.2;for (map::iterator it = m.begin(); it != m.end();it++){for ( map::iterator it2= it->second.begin(); it2 != it->second.end();it2++){cout firstmapcout array1,2,3,4,5,6};coutcoutSetConsoleOutputCP ( CP_UTF8 );test1();system("pause");return 0;}public: struct Store{int id;int value;bool status;};void test6(int number);private:Store a;};void my_print(const myclass::Store &store){coutif(number==0){a.id=0; a.value=0; a.status=false;}else{a.id =1;a.status=true;a.value =number;}myclass::Store & s= a;coutSetConsoleOutputCP ( CP_UTF8 );myclass c;c.test6(0);c.test6(1);c.test6(0);system("pause");return 0;} std::function} void notify() { callback_(); }}; class Foo{public: void operator()(void) { std::cout if (x % 2 == 0) { f(x); }else {f(0);}} void output(int x){ std::coutSetConsoleOutputCP ( CP_UTF8 ); Foo foo; A aa(foo); aa.notify(); call_when_even(1,output);system("pause");return 0;}public: A(){coutcoutcoutpublic: C(){coutcoutcoutpublic:B(){cout coutB b;}int main() {SetConsoleOutputCP ( CP_UTF8 );if(-1)test();system("pause");return 0;}cout cout int g =100;fun( 1,[&](int d, int e){g++; fun2(d,e);cout SetConsoleOutputCP ( CP_UTF8 );test();system("pause");return 0;}结果打印:fun: 1fun 内的 f 函数fun2: b+c = 10operator(): g = 101fun 内的 d 函数fun2: b+c = 99operator(): g = 102GROUP_1=0,GROUP_2=1, GROUP_3=2, GROUP_4=3, GROUP_5=4, GROUP_6=5,};class A{public:struct Store{int id;arraycout cout m_map[GROUP_1][0].id = 1;m_map[GROUP_1][1].data.fill(0x02);for(int i=0; icout coutSetConsoleOutputCP ( CP_UTF8 );A a;a.initStore();system("pause");return 0;}运行结果:A 构造2 ID =1 :0 0 0 0 0 0 0 02 ID =0 :2 2 2 2 2 2 2 22 ID =0 :0 0 0 0 0 0 0 03 ID =0 :0 0 0 0 0 0 0 04 ID =0 :0 0 0 0 0 0 0 0