| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 633 人关注过本帖
标题:vector来统计单词
取消只看楼主 加入收藏
linlin
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2006-3-14
收藏
 问题点数:0 回复次数:1 
vector来统计单词
求,以下是将一些字符信息写入到指定文件中
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
fstream outfile;
outfile.open("file1.dat",ios::out);
if(!outfile)
{
cout<<"file1.dat can't open.\n";
abort();
}
outfile<<"this is a program.\n";
outfile<<"this is a string.";
outfile<<"\nok!";
outfile.close();
return 0;
}
然后我要统计文件file1.dat中单词个数,写了以下程序
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int main()
{

ifstream in("file1.dat",ios::in);

vector <string> words;
string word;
while(in>>word)
words.push_back(word);
cout<<v.size();
in.close();
return 0;
}
果发现不能求出单词个数,有编译错误,寻求高人指点,谢谢了
搜索更多相关主题的帖子: vector 单词 统计 
2006-03-16 18:28
linlin
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2006-3-14
收藏
得分:0 

谢谢woodhead!我改过来了,但是如下这个程序在VC6.0中为什么会有警告呢?而在DEV-C++中运行正常呢,
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int main()
{

ifstream in("file1.dat",ios::in);

vector <string> words;
string word;
while(in>>word)
words.push_back(word);
cout<<words.size();
in.close();
return 0;
} 这个是VC的警告
---Configuration: Cpp3 - Win32 Debug--------------------
Compiling...
Cpp3.cpp
D:\新建文件夹\Cpp3.cpp(18) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_tra
its<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
D:\新建文件夹\Cpp3.cpp(18) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<ch
ar>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
d:\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std
::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
d:\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<st
d::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information

Cpp3.obj - 0 error(s), 4 warning(s)
你知道为什么会这样吗,谢谢


woyaochengshuyidianle 我真的什么也不会
2006-03-16 20:26
快速回复:vector来统计单词
数据加载中...
 
   



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

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