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 817 views
817 views asked Feb 1, 2018 by avibootz
2 answers 300 views
1 answer 277 views
1 answer 320 views
1 answer 1,045 views
1 answer 187 views
...