编译后 0 error(s), 226 warning(s) 。。。。。。。。。
这么多的 warning(s)
虽然不影响程序!
但总归是不安全的!
这是Essential C++中的一个练习,根据答案写的结果!
我能就这样把它放到一边!!继续往下走吗??
我打得这个程序:
//colume.cpp
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void initialize_exclusion_set( set<string>& );
void process_file( map<string,int>&, const set<string>&, ifstream& );
void user_query( const map<string,int>& );
void display_word_count( const map<string,int>&, ofstream& );
main()
{
ifstream ifile( "column.txt" );
ofstream ofile( "colume.map" );
if ( !ifile || !ofile )
{
cerr << "Unable to open the file ---bailing out!\n";
return -1;
}
set<string> exclude_set;
initialize_exclusion_set( exclude_set );
map<string,int> word_count;
process_file( word_count, exclude_set, ifile );
user_query( word_count );
display_word_count( word_count, ofile);
}
void initialize_exclusion_set( set<string>&exs )
{
static string _exclude_word[25]={
"the","end","but","that","then","are","been",
"can","a","could","did","for","of",
"had","have","him","his","her","its","is",
"were","which","when","with","would"
};
exs.insert( _exclude_word, _exclude_word+25 );
}
void process_file( map<string,int> &word_count, const set<string> &exclude_set,ifstream &ifile)
{
string word;
while ( ifile >> word )
{
if ( exclude_set.count( word ))
continue;
word_count[ word ]++;
}
}
void user_query( const map<string,int> &word_map )
{
string search_word;
cout << "Please enter a word to search: q to quit ";
cin >> search_word;
while ( search_word.size() && search_word != "q")
{
map<string,int>::const_iterator it;
if ( ( it = word_map.find( search_word ) ) != word_map.end() )
cout << "Found! " << it->first
<< " occurs " << it->second
<< " times.\n";
else cout << search_word
<< "was not found in text.\n";
cout << "\nAnother search? (q to quit)";
cin >> search_word;
}
}
void display_word_count( const map<string,int> &word_map, ofstream &os )
{
map<string,int>::const_iterator iter = word_map.begin(),
end_it = word_map.end();
while ( iter != end_it )
{
os << iter->first << "(" << iter->second << ")" << endl;
++iter;
}
os << endl;
}
//column.txt
MooCat is a long-haired white kitten with large
black pathches Like a cow looks only he is a kitty
poor kitty Alice says cradling MooCat in her arms
pretending he is not struggling to break free
问题点数:20、回复次数:9Top
1 楼freezingfire(让美梦来得更猛烈些吧)回复于 2002-05-23 09:28:37 得分 0
warning是什么?如果是那种字符标识超长,可以解决的。
编译程序最好做到0 error,0 warning。Top
2 楼yzfhappy(冷虎)回复于 2002-05-23 09:33:55 得分 0
出现这样的问题,一般是你定义了某个变量但没有使用,就是没有赋值,有时也是你的函数没有返回值。一般用C++编程时,定义了一个函数都得有返回值(除非你定义的是VOID型)即return;
你最好先把这个弄明白了再往下走,这个虽然不防碍程序的运行,但却是浪费了许多资源,也有很多潜在的BUG。Top
3 楼zhdleo(叮东)回复于 2002-05-23 09:35:18 得分 0
都是类似这样
see reference to class template instantiation 'std::set<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
的set map的错误!Top
4 楼lbaby(春天来了...)回复于 2002-05-23 09:37:14 得分 0
可以不用管的
但是最好管一管
就有这样专门挑毛病的程序
Top
5 楼hwei75()回复于 2002-05-23 09:38:21 得分 10
在文件开头加上
#pragma warning(disable: 4786)
该警告是因为在模板的形式类型在编译中会被实际类型替换。经过多层替换后,标识符长度超过255个字符的限制。而加上的一句屏蔽该警告。这不是什么问题。不用理它。详细情况在MSDN中输入4786搜索。Top
6 楼zhdleo(叮东)回复于 2002-05-23 09:44:18 得分 0
#pragma warning(disable: 4786)
我试过了,的确可以!!!
太好了!
不过我不理解!能解释一下吗?
因为我的MSDN用不成!Top
7 楼JoeXu(我是一个诗人)回复于 2002-05-23 09:48:10 得分 0
是的,我也遇到map的时候有warning,#pragma warning(disable: 4786)
Top
8 楼step_by_step(脚印)回复于 2002-05-23 10:30:30 得分 10
因为编译器在编译时会把模板展开,经过多次的展开后,所生成的标识符长度很可能就超过规定的最大长度255个字符,所以此时编译器就会把超过长度的字符串切去并且告警。加上
#pragma warning(disable: 4786)这一句就行了。此句在msdn中的解释如下
'identifier' : identifier was truncated to 'number' characters in the debug information
The identifier string exceeded the maximum allowable length and was truncated.
The debugger cannot debug code with symbols longer than 255 characters. In the debugger, you cannot view, evaluate, update, or watch the truncated symbols.
This limitation can be overcome by shortening identifier names. The example code below demonstrates this method.
A trace mechanism can also be used to solve this problem. A trace mechanism is like the printf statements in the code. It keeps track of what is going on in an application during the debugging process. The _ASSERT, _ASSERTE, _RPTn and _RPTFn macros provide concise and flexible ways to perform the trace. These macros are not defined when _DEBUG is not defined. See Using Macros for Verification and Reporting for more information.
This warning is off by default. See Compiler Warnings That Are Off by Default for more information.
Top
9 楼zhdleo(叮东)回复于 2002-05-23 10:43:20 得分 0
谢谢大家了!Top
相关问题
- VC编译得到的:warning!
- 预编译头 error C2857 ?
- *****---声明vector编译时warning的问题---*****
- 编译错误:warning: missing braces around initializer
- 编译时出现大量的WARNING
- 急急!!!c++b编译时两句错误提示[Linker Error]Fatal:Error delected(LME279)[Linker Warning]Out of memory
- 请问是否有这样的预编译语句,让程序编译时报error然后中止编译?
- 编译怎么有一处syntax error:']'
- 编译出错,fatal error C1010: 请指教!
- 编译错误:Command line error D2016 : '/ZI' and '/O2'




