这将打印的地址我的字符串,而不是它的内容,ostream的,复印功能打印字符串的地址,而不是字符串内容
#include <memory>
#include <string>
#include <list>
#include <iostream>
#include <iterator>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
unique_ptr<list<shared_ptr<string>>> upList (new list<shared_ptr<string>>);
shared_ptr<string> spNation (new string ("India"));
upList->push_back (spNation);
copy (upList->begin(), upList->end(), ostream_iterator<shared_ptr<string>> (cout, "\n "));
return 0;
}
我的问题是:
- 正在采取什么
ostream_iterator<shared_ptr<string>>
shared_ptr或字符串作为其主要对象。 - 如何使用此方法打印实际字符串内容(即印度)。
- 这种方法比传统的for循环更适合打印所有节点内容。
你不需要shared_ptr,字符串就足够好了 –
piokuc
2013-04-09 08:46:20