首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

麻烦帮忙看一下4个警告,小弟我看不懂,多谢

2012-04-19 
麻烦帮忙看一下4个警告,我看不懂,谢谢C/C++ code#include iostream#include vector#include string#

麻烦帮忙看一下4个警告,我看不懂,谢谢

C/C++ code
#include <iostream>#include <vector>#include <string>#include <iterator>#include <algorithm>using namespace std;const char table[27] = {"22233344455566670778889990"};void trans(string & num);void main(){    string phone;    vector<string> allphone;    vector<string> temp;    vector<string>::iterator ite;    int size;    cout << "请输入测试元素的个数:";    cin >> size;    fflush( stdin );    cout << "请输入电话号码:" << endl;    for (int i = 0; i < size; ++i)    {        getline(cin, phone);        trans( phone );        allphone.push_back( phone );    }    sort(allphone.begin(), allphone.end());    cout << "重复的电话号码有:" << endl;    ite = allphone.begin();    while (ite != allphone.end())    {        string target = *ite;        int count = 0;        bool flag =  false;        while (target == *ite)        {            count++;            ite++;            if (ite == allphone.end())            {                flag = true;                break;            }        }                if (count < 2)        {            continue;        }        else        {            cout << target << ' ' << count << endl;        }                if (flag)        {            break;        }            }        }void trans(string & num){    string::iterator i;            for (i = num.begin(); i != num.end(); ++i)    {        if (isdigit(*i))        {            continue;        }        else if (*i == '-')        {            num.erase(i);            --i;            continue;        }        else        {            if (*i >= 'a' && *i <= 'z')            {                *i -= 32;            }            *i = ( table[*i - 'A'] );        }    }    num.insert(3, 1, '-');}

********************************************************************
Compiling...
2.cpp
D:\struct data\7\2.cpp(78) : 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:\struct data\7\2.cpp(78) : 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
c:\program files\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
c:\program files\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<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

2.obj - 0 error(s), 4 warning(s)

[解决办法]
报警时由于类名超过了255个字,使用时就会报4786的waring。在使用STL(C++标准模板库)的时候经常引发类似的错误,尤其是vector,map这类模板类,模板中套模板,一不小心就超长了。
解决方法有两种,一种是直接定义别名:
#ifdef _DEBUG
#define VeryLongClassNameA A
#define VeryLongClassNameB B
#endif

另一种是屏蔽4786warning:
#pragma warning(disable : 4786)

注意屏蔽语句必须放在报错的模板类的引用声明(如#include <vector>)之前,否则还是不起作用。


[解决办法]
对于vector和list,一个是使用连续的内存区间,类似一个数组,一个使用的是链表,对于他们之间的优缺点,相信楼主应该清楚吧~~~
[解决办法]
g++编译也没有你那种提示

如果是学习的话, 换编译器吧, VS2010, g++
小程序, code::blocks, c-free, dev-c++这写IDE都可以试试, vc6.0太老了, 很多东西和标准不一致
[解决办法]
VC6应该淘汰了

用typedef 定义 一些迭代器

例:
typedef vector<int>::const_iterator v_int_cint;

热点排行