How to create initialize and print a shared_ptr in C++

1 Answer

0 votes
#include <iostream>
#include  <memory>

using std::cout;
using std::endl;

int main()
{
	std::shared_ptr<int> p = std::make_shared<int>();

	*p = 13;
	
	cout << *p << endl;
	cout << p << endl;

	return 0;
}


/*
run:

13
00446044

*/

 



answered Jan 31, 2018 by avibootz

Related questions

7 answers 429 views
429 views asked Feb 1, 2018 by avibootz
2 answers 116 views
1 answer 149 views
1 answer 193 views
1 answer 899 views
...