刚学C++,写例子程序的时候碰到了一个问题!
我的代码如下:
#include <stdio.h>
#include <vector>
#include <list>
#include <deque>
#include <iostream>
#include <stdexcept>
#include <stack>
#include <utility>
#include <map>
#include <sstream>
#include <fstream>
using std::vector;
using std::list;
using std::deque;
using std::cin;
using std::cout;
using std::cerr;
using std::string;
using std::endl;
using std::stack;
using std::pair;
using std::map;
using std::getline;
using std::make_pair;
using std::runtime_error;
using std::istringstream;
using std::ifstream;
int main(int argc, char *argv[])
{
vector < vector < string > > vecChildName;
vector < string > vecFamilyName;
map < string, vector < string > > mapFamily;
string strMyName = "Bruce ";
vecFamilyName.push_back( "Zhao " );
vecFamilyName.push_back( "Lee " );
vecFamilyName.push_back( "Zhang " );
vecFamilyName.push_back( "Wang " );
vecFamilyName.push_back( "Yang " );
vecFamilyName.push_back( "Bai " );
vector < string > vecTmpName;
for( int i = 0; i < 6 ; ++i )
{
for( int j = 0; j < 6; ++j )
{
vecTmpName.push_back( strMyName + vecFamilyName[ i ] );
}
vecChildName.push_back( vecTmpName );
}
for( int i = 0; i < 6; ++i )
{
mapFamily.insert( make_pair( vecFamilyName[ i ], vecChildName[ i ] ) );
}
map < string, vector < string > > ::const_iterator map_it;
vector < string > ::iterator iterChildName;
string strFamilyName;
while( cin > > strFamilyName, !cin.eof() )
{
map_it = mapFamily.find( strFamilyName );
if( map_it == mapFamily.end() )
{
cout < < "Your input the key " < < strFamilyName
< < ", not the value! " < < endl;
}
else
{
vecTmpName = map_it-> second; // 这里应该如何处理
iterChildName = vecTmpName.begin();
cout < < "Family Name: " < < map_it-> first < < endl;
while( iterChildName != vecTmpName.end() )
{
cout < < " " < < *iterChildName < < endl;
++iterChildName;
}
}
}
return 0;
}
像上面的例子当中,如果我输入 "Lee ", 输出的确是从BruceZhao到BruceLee的所有项,我不清楚到底我哪里错了?应该如何改正? 先谢了!
[解决办法]
自己去一步一步调试吧,f5,断点,f10,f11
[解决办法]
没明白问题······
[解决办法]
楼主,不明白你的意图是想干什么啊。