今天写了一段代码要求实现:
从标准输入读取字符串并将他们存储为类模板(vector)对象,并从类模板中将其输出。
程序编译后提示有4个警告如下:
warningC4786: '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<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' chara
cters in the debug information
我是初学者,这个警告好像是内存出了问题,请大家帮我大概解释一下这里的提示是什么意思。
还有一个问题,我可能是少引用了一个std命名空间中的操作,所以在编译过程中总是出错,但是加上using namespace std;后就能编译通过了。请大家帮我看一下是缺了哪个std中的操作。
代码如下:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main()
{
vector<string> text;
string word;
while(cin>>word)
{
text.push_back(word);
}
for(vector<int>::size_type index=0;index!=text.size();index++)
cout<<text[index]<<" ";
cout<<endl;
return 0;
}
还有我刚开始学习C++,代码中有什么其他的不足希望大家多多斧正。
main函数的应用程序的入口函数指的是while(cin>>word){text.push_back(word);}吗?如果是的话说他不能定义成模板函数,这是为什么呢?这样做程序可以正常运行,会带来哪些潜在的威胁呢?还有您推荐的以查相关的书籍《thinking in C++》《stl 源码剖析》在网上可以找到电子版吗?或者哪些是值得推荐仔细研读的。不然为了一个问题去买两本书个人觉得有点事倍功半的意思。望指教。
我知道使用using namespace std;是包含下面的操作,只是在编写头文件的时候,所有的引用于std的操作需要通过using std::XXX的方式声明。我想知道如果去掉using namespace std;而全部改为using std::XXX声明,我的代码中缺少什么。
追答我试过了,目前你代码里面不用using namespace std;采用你的方式也能编译和执行,不缺少什么.
本回答被提问者采纳