środa, 8 lutego 2023

Project files in ListBoxes - Visual C++


 #pragma endregion

private:

String^ char_to_String(char* value)

{

String^ result = gcnew String(value);

return result;

}

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

char* name1 = "Form1.h";

char* name2 = "Form1.cpp";

char* name3 = "pch.h";

char* name4 = "pch.cpp";

char* name5 = "Resource.h";

String^ temp;

char buff1[10000], buff2[10000], buff3[10000], buff4[10000], buff5[10000];

ifstream file1(name1);

if (file1.is_open())

{

while (file1.getline(buff1, 1000))

{

temp = char_to_String(buff1);

listBox1->Items->Add(temp);

}

file1.close();

}

ifstream file2(name2);

if (file2.is_open())

{

while (file2.getline(buff2, 1000))

{

temp = char_to_String(buff2);

listBox2->Items->Add(temp);

}

file2.close();

}

ifstream file3(name3);

if (file3.is_open())

{

while (file3.getline(buff3, 1000))

{

temp = char_to_String(buff3);

listBox3->Items->Add(temp);

}

file3.close();

}

ifstream file4(name4);

if (file4.is_open())

{

while (file4.getline(buff4, 1000))

{

temp = char_to_String(buff4);

listBox4->Items->Add(temp);

}

file4.close();

}

ifstream file5(name5);

if (file5.is_open())

{

while (file5.getline(buff5, 1000))

{

temp = char_to_String(buff5);

listBox5->Items->Add(temp);

}

file5.close();

}


}

czwartek, 2 lutego 2023

STL, shared_ptr, make shared - example g++ console

#include <iostream>

#include <string>

#include <memory>


using namespace std;


class CPU

{

public:

    string model_Name;

    int cache_Size;

    double cpu_MHz;


    CPU(string a1, int a2, double a3)

    {

        model_Name=a1;

        cache_Size=a2;

        cpu_MHz=a3;

        cout<<"START\n";

    }


    ~CPU()

    {

        cout<<"END\n";

    }


};


shared_ptr<double>shared_Double;

shared_ptr<int>shared_Int;

shared_ptr<string>shared_String;


int main()

{

 auto date_CPU(make_shared<CPU>("Pentium III",1024,900.65));

 shared_Double=shared_ptr<double>(date_CPU,&date_CPU->cpu_MHz);

 shared_Int=shared_ptr<int>(date_CPU,&date_CPU->cache_Size);

 shared_String=shared_ptr<string>(date_CPU,&date_CPU->model_Name);

 cout<<"Report CPU: \n";

 cout<<"Model:  "<<*shared_String<<endl;

 cout<<"Cache: "<<*shared_Int<<endl;

 cout<<"MHz: "<<*shared_Double<<endl;

    return 0;

}