标题:[求助]关于namespace的问题
取消只看楼主
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
 问题点数:0 回复次数:1 
[求助]关于namespace的问题

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
int num = 1;//计数
string word;//输入及记录单词
vector<string> vec;//储存文章

while (cin>>word && word[0] != '0')
{
vec.push_back(word);
}

vector<string>::iterator iter1 = vec.begin();
vector<string>::iterator iter2 = vec.begin();
word = *iter2++;

while(iter2 != vec.end())
{
if (*iter1++ == *iter2++)
if (*iter1 == word)
++num;
else
{
int fnum = 2;
while (*iter1 == *iter2 && iter2 != vec.end())
{
++fnum;
++iter1;
++iter2;
}
if(fnum >= num)
{
word = *iter1;
num = fnum;
}
}
}
cout << word << "连续出现了" << num << "次" <<endl;
return 0;
}
--------------------VC++6.0编译-------------------------------------------------
输入:a a a b b b b a a a c c c c c b 0
打印:c连续出现了5次
--------------------------------------------------------------------------------
为什么把
using namespace std;
换成
using std::string;
using std::vector;
using std::iterator;
using std::cin;
using std::cout;
using std::endl;
会出错

搜索更多相关主题的帖子: namespace vector string word include 
2006-12-16 23:22
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
得分:0 
?/?????

为了C++,我放弃了课本
为了高考,我又放弃了C++
现在而今眼目下,我能做什么?www.
2006-12-17 14:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-110023-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.739212 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved