Ну, как-то так:
#include <iostream>
#include <map>
#include <vector>
#include <memory>
using namespace std;
struct node { multimap<string, shared_ptr<node>> childs; };
void print(const shared_ptr<node>& c, const size_t n)
{
for (auto p : c->childs) {
for (size_t i=0; i<n; i++) cout << '\t';
cout << p.first << "\n";
print(p.second, n+1);
}
}
int main()
{
vector<shared_ptr<node>> lasts;
lasts.push_back(make_shared<node>());
auto add = [&](string name) {
auto n = make_shared<node>();
lasts.back()->childs.insert({name, n});
lasts.push_back(n);
};
string line;
while (getline(cin, line)) {
auto first = line.find_first_not_of('\t');
while (lasts.size()>first+1) lasts.pop_back();
while (lasts.size()<first+1) add("");
add(string(line, first));
}
print(lasts.front(),0);
return 0;
}
Работает на однобайтовых кодировках.