Skip to content
Snippets Groups Projects
Commit f28040a9 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele 13.4.2023

parent cf5e8c05
Branches
No related tags found
No related merge requests found
Showing
with 436 additions and 0 deletions
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *hello = new string ("Hello, world!");
cout << *hello << endl;
return 0;
}
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *hello = new string ("Hello, world!");
cout << *hello << endl;
delete hello;
cout << *hello << endl;
return 0;
}
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *hello = new string ("Hello, world!");
cout << *hello << endl;
delete hello;
if (hello)
cout << *hello << endl;
else
cout << "Variable wurde bereits freigegeben." << endl;
return 0;
}
#include <stdio.h>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *hello = new string ("Hello, world!");
printf ("hello = 0x%016zx\n", (size_t) hello);
cout << *hello << endl;
delete hello;
printf ("hello = 0x%016zx\n", (size_t) hello);
if (hello)
cout << *hello << endl;
else
cout << "Variable wurde bereits freigegeben." << endl;
return 0;
}
#include <stdio.h>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *hello = new string ("Hello, world!");
printf ("hello = 0x%016zx\n", (size_t) hello);
cout << *hello << endl;
delete hello;
hello = NULL;
printf ("hello = 0x%016zx\n", (size_t) hello);
if (hello)
cout << *hello << endl;
else
cout << "Variable wurde bereits freigegeben." << endl;
return 0;
}
#include <stdio.h>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *hello;
if (hello)
cout << *hello << endl;
else
cout << "Kein gültiger Zeiger." << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
int main ()
{
shared_ptr <string> hello = new string ("Hello, world!");
if (hello)
cout << *hello << endl;
else
cout << "Kein gültiger Zeiger." << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
int main ()
{
shared_ptr <string> hello (new string ("Hello, world!"));
if (hello)
cout << *hello << endl;
else
cout << "Kein gültiger Zeiger." << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
int main ()
{
shared_ptr <string> hello ("Hello, world!");
if (hello)
cout << *hello << endl;
else
cout << "Kein gültiger Zeiger." << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
int main ()
{
shared_ptr <string> hello2;
if (hello2)
cout << *hello2 << endl;
else
cout << "(String noch nicht vorhanden)" << endl;
if (1)
{
shared_ptr <string> hello (new string ("Hello, world!"));
cout << *hello << endl;
hello2 = hello;
}
cout << *hello2 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
struct container
{
string content;
container (const char *s)
{
content = s;
}
shared_ptr <container> next;
};
int main ()
{
shared_ptr <container> hello1 (new container ("Hello,"));
shared_ptr <container> hello2 (new container ("world!"));
cout << hello1->content << " " << hello2->content << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
struct container
{
string content;
container (const char *s)
{
content = s;
}
shared_ptr <container> next;
};
int main ()
{
shared_ptr <container> hello1 (new container ("Hello,"));
shared_ptr <container> hello2 (new container ("world!"));
hello1->next = hello2;
hello2->next = hello1;
cout << hello1->content << " " << hello2->content << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
struct container
{
string content;
container (const char *s)
{
content = s;
}
~container ()
{
cout << "Bye: " << content << endl;
}
shared_ptr <container> next;
};
int main ()
{
shared_ptr <container> hello1 (new container ("Hello,"));
shared_ptr <container> hello2 (new container ("world!"));
// hello1->next = hello2;
// hello2->next = hello1;
cout << hello1->content << " " << hello2->content << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
struct container
{
string content;
container (const char *s)
{
content = s;
}
~container ()
{
cout << "Bye: " << content << endl;
}
shared_ptr <container> next;
};
int main ()
{
shared_ptr <container> hello1 (new container ("Hello,"));
shared_ptr <container> hello2 (new container ("world!"));
hello1->next = hello2;
hello2->next = hello1;
cout << hello1->content << " " << hello2->content << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
using std::weak_ptr;
struct container
{
string content;
container (const char *s)
{
content = s;
}
~container ()
{
cout << "Bye: " << content << endl;
}
weak_ptr <container> next;
};
int main ()
{
shared_ptr <container> hello1 (new container ("Hello,"));
shared_ptr <container> hello2 (new container ("world!"));
hello1->next = hello2;
hello2->next = hello1;
cout << hello1->content << " " << hello2->content << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
using std::weak_ptr;
int main ()
{
weak_ptr <string> p;
shared_ptr <string> hello (new string ("Hello, world!"));
p = hello;
cout << *p << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
using std::weak_ptr;
int main ()
{
weak_ptr <string> p;
shared_ptr <string> hello (new string ("Hello, world!"));
p = hello;
shared_ptr <string> q = p.lock ();
cout << *q << endl;
return 0;
}
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main ()
{
string *p;
string *hello = new string ("Hello, world!");
p = hello;
string *q = p;
cout << *q << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
using std::weak_ptr;
int main ()
{
weak_ptr <string> p;
shared_ptr <string> hello (new string ("Hello, world!"));
p = hello;
shared_ptr <string> q = p.lock ();
if (q)
cout << *q << endl;
else
cout << "Zeiger wurde bereits freigegeben." << endl;
return 0;
}
#include <iostream>
#include <string>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::shared_ptr;
using std::weak_ptr;
int main ()
{
weak_ptr <string> p;
if (1)
{
shared_ptr <string> hello (new string ("Hello, world!"));
p = hello;
}
shared_ptr <string> q = p.lock ();
if (q)
cout << *q << endl;
else
cout << "Zeiger wurde bereits freigegeben." << endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment