| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1524 人关注过本帖
标题:[求助] 编译无法通过
只看楼主 加入收藏
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
 问题点数:0 回复次数:11 
[求助] 编译无法通过

#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<map>
#include<set>

#include<stddef.h>
#include<ctype.h>

vector<string,allocator>* retrieve_text()
{
ifstream infile("test.txt",ios::in);
if (!infile) {
cerr <<"can't open file"<<endl;
exit(-1);
}
else cout<<'\n';
vector<string,allocator> *lines_of_text = new vector<stirng,allocator>;
string textline;
typedef pair<string::size_type,int> stats;
stats maxline;
int linenum = 0;
while(getline(infile,textline,'\n') {
cout<<"line read: "<<textline<<\n;
if(maxline.first << textline.size()) {
maxline.first = textline.size();
maxline.second = linenum;
}
lines_of_text->push_back(textline);
linenum++;
}
return lines_of_text;
}

int main()
{
return 0;
}

搜索更多相关主题的帖子: 编译 
2006-03-09 16:12
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
错误呢?

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-03-09 16:22
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 
error C2143: syntax error : missing ';' before '<'
error C2501: 'vector' : missing storage-class or type specifiers
error C2143: syntax error : missing ';' before '<'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2017: illegal escape sequence

未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-09 16:55
olivezhang
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-9-14
收藏
得分:0 

#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<map>
#include<set>
#include <IOSTREAM> //头文件漏了
#include <FSTREAM>

using namespace std;
#include<stddef.h>
#include<ctype.h>

vector<string>* retrieve_text() //使用默认参数
{
ifstream infile("test.txt",ios::in);
if (!infile) {
cerr <<"can't open file"<<endl;
exit(-1);
}
else cout<<'\n';
vector<string> *lines_of_text = new vector<string>;//使用默认参数, string拼写错误为stiring
string textline;
typedef pair<string::size_type,int> stats;
stats maxline;
int linenum = 0;
while(getline(infile,textline,'\n')) { //缺了括号
cout<<"line read: "<<textline<<'\n'; //此处漏了单引号
if(maxline.first << textline.size()) {
maxline.first = textline.size();
maxline.second = linenum;
}
lines_of_text->push_back(textline);
linenum++;
}
return lines_of_text;
}

int main()
{
retrieve_text();

int a;
cin >> a;
system("pause");

return 0;
}

[此贴子已经被作者于2006-3-9 16:56:33编辑过]


谷底深深行 ,峰顶漫漫步......@_@
2006-03-09 16:55
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 
vector<string,allocator>* retrieve_text()
vector<string>* retrieve_text() //使用默认参数

为什么呀?

未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-09 17:06
olivezhang
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-9-14
收藏
得分:0 
1。template <class Type, class Allocator = allocator<Type>>
class vector
可见,第二个参数为默认参数。
2。如果一定要显式用第二个参数,用法如下(蓝色):
typedef allocator<string> allo_str;

#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<map>
#include<set>
#include <IOSTREAM> //头文件漏了
#include <FSTREAM>

using namespace std;
#include<stddef.h>
#include<ctype.h>

vector<string, allo_str>* retrieve_text() //使用默认参数
{
ifstream infile("test.txt",ios::in);
if (!infile) {
cerr <<"can't open file"<<endl;
exit(-1);
}
else cout<<'\n';
vector<string, allo_str> *lines_of_text = new vector<string, allo_str>;//使用默认参数, string拼写错误为stiring
string textline;
typedef pair<string::size_type,int> stats;
stats maxline;
int linenum = 0;
while(getline(infile,textline,'\n')) { //缺了括号
cout<<"line read: "<<textline<<'\n'; //此处漏了单引号
if(maxline.first << textline.size()) {
maxline.first = textline.size();
maxline.second = linenum;
}
lines_of_text->push_back(textline);
linenum++;
}
return lines_of_text;
}

int main()
{
retrieve_text();

int a;
cin >> a;
system("pause");

return 0;
}


谷底深深行 ,峰顶漫漫步......@_@
2006-03-09 18:03
olivezhang
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-9-14
收藏
得分:0 
typedef allocator<string> allo_str;表示要为string类型分配空间,其实默认参数就这意思,所以用默认参数方便。。。。

谷底深深行 ,峰顶漫漫步......@_@
2006-03-09 18:06
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 

非常感谢!
以下是完整代码,但是还是编译不通过。

#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<map>
#include<set>

#include<iostream>
#include<fstream>
using namespace std;

#include<stddef.h>
#include<ctype.h>


typedef pair<short,short>location;
//typedef vector<location,allocator>loc;
typedef vector<location>loc;
//typedef vector<string,allocator>text;
typedef vector<string>text;
typedef pair<text*,loc*>text_loc;

class TextQuery {
public:
TextQuery() { memset(this,0,sizeof(TextQuery)); }
static void filter_elements(string felems) { filt_elems = felems; }
void query_text();
void display_map_text();
void display_text_locations();
void doit() {
retrieve_text();
separate_words();
filter_text();
suffix_text();
strip_caps();
build_word_map();
}
private:
void retrieve_text();
void separate_words();
void filter_text();
void strip_caps();
void suffix_text();
void suffix_s(string&);
void build_word_map();
private:
// vector<string,allocator> *lines_of_text;
vector<string> *lines_of_text;
text_loc *text_locations;
// map<string,loc*,less<string>,allocator> *word_map;
map<string,loc*> *word_map;
static string filt_elems;
};
string TextQuery::filt_elems("\",.;:!<<)(\\/");

int main()
{
TextQuery tq;
tq.doit();
tq.query_text();
tq.display_map_text();

return 0;
}

void TextQuery::retrieve_text()
{
string file_name;
cout << "please enter file name: ";
cin >> file_name;
ifstream infile(file_name.c_str(),ios::in);
if (!infile) {
cerr << "oops! unable to open file"
<< file_name << "--bailing out!\n";
exit(-1);
} else cout << "\n";
// lines_of_text = new vector<string,allocator>;
lines_of_text = new vector<string>;
string textline;
while (getline(infile,textline,'\n'))
lines_of_text->push_back(textline);
}

void TextQuery::separate_words()
{
// vector<string, allocator> *words = new vector<string,allocator>;
vector<string> *words = new vector<string>;
// vector<location,allocator> *locations = new vector<location,allocator>;
vector<location> *locations = new vector<location>;

for (short line_pos = 0; line_pos < lines_of_text->size(); line_pos++) {
short word_pos = 0;
string textline = (*lines_of_text)[line_pos];
string::size_type eol = textline.length();
string::size_type pos = 0,prev_pos = 0;

while ((pos = textline.find_first_of(' ',pos)) != string::npos) {
words->push_back(textline.substr(prev_pos,pos-prev_pos));
locations->push_back(make_pair(line_pos,word_pos));
word_pos++; pos++;prev_pos = pos;
}
words->push_back(textline.substr(prev_pos,pos - prev_pos));
locations->push_back(make_pair(line_pos,word_pos));
}
text_locations = new text_loc(words,locations);
}

void TextQuery::filter_text()
{
if (filt_elems.empty())
return;
// vector<string,allocator> *words = text_locations->first;
vector<string> *words = text_locations->first;
// vector<string,allocator>::iterator iter = words->begin();
vector<string>::iterator iter = words->begin();
// vector<string,alocator>::iterator iter_end = words->end();
vector<string>::iterator iter_end = words->end();

while (iter != iter_end) {
string::size_type pos = 0;
while ((pos = (*iter).find_first_of(filt_elems,pos)) != string::npos)
(*iter).erase(pos,1);
++iter;
}
}

void TextQuery::suffix_text()
{
// vector<string,allocator> *words = text_locations->first;
vector<string> *words = text_locations->first;
// vector<string,allocator>::iterator iter = words->begin();
vector<string>::iterator iter = words->begin();
// vector<string,allocator>::iterator iter_end = words->end();
vector<string>::iterator iter_end = words->end();

while (iter != iter_end) {
if ((*iter).size() <= 3) {
iter++;
continue;
}
if ((*iter)[(*iter).size() -1] = 's')
suffix_s(*iter);
iter++;
}
}

void TextQuery::suffix_s(string &word)
{
string::size_type spos = 0;
string::size_type pos3 = word.size() - 3;
string suffixes("oussisius");

if (!word.compare(pos3,3,suffixes,spos,3) ||
!word.compare(pos3,3,suffixes,spos+6,3) ||
!word.compare(pos3+1,2,suffixes,spos+2,2) ||
!word.compare(pos3+1,2,suffixes,spos+4,2))
return;
string ies("ies");
if (!word.compare(pos3,3,ies)) {
word.replace(pos3,3,1,'y');
return;
}
string ses("ses");
if (!word.compare(pos3,3,ses)) {
word.erase(pos3+1,2);
return;
}
word.erase(pos3+2);

if(word[pos3+1] == '\'')
word.erase(pos3+1);
}

void TextQuery::strip_caps()
{
// vector<string,allocator> *words = text_locations->first;
vector<string> *words = text_locations->first;
// vector<string,allocator>::value_type iter = words->begin();
vector<string>::iterator iter = words->begin();
// vector<string,allocator>::iterator iter_end = words->end();
vector<string>::iterator iter_end = words->end();

string caps("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
while(iter != iter_end) {
string::size_type pos = 0;
while ((pos = (*iter).find_first_of(caps,pos)) != string::npos)
(*iter)[pos] = tolower((*iter)[pos]);
++iter;
}
}


void TextQuery::build_word_map()
{
// word_map = new map<string,loc*,less<string>,allocator>;
word_map = new map<string,loc*>;
// typedef map<string,loc*,less<string>,allocator>::value_type value_type;
typedef map<string,loc*>::value_type value_type;
// typedef set<string,less<string>,allocator>::difference_type diff_type;
typedef set<string>::difference_type diff_type;
//set<string,less<string>,allocator>exclusion_set;
set<string>exclusion_set;
ifstream infile("exclusion_set");

if (!infile) {
static string default_excluded_words[25] = {
"the","and","but","that","then","are","been",
"can","can't","cannot","could","did","for",
"had","have","him","his","her","its","into",
"were","which","when","with","would"
};
cerr<<"warning! unable to open word exclusion file! --"
<<"using default set\n";
copy(default_excluded_words,default_excluded_words+25,
inserter(exclusion_set,exclusion_set.begin()));
} else {
istream_iterator<string,diff_type>
input_set(infile),eos;
copy(input_set,eos,
inserter(exclusion_set,exclusion_set.begin()));
}

// vector<string,allocator> *text_words = text_locations->first;
vector<string> *text_words = text_locations->first;
// vector<location,allocator> *text_locs = text_locations->second;
vector<location> *text_locs = text_locations->second;

register int elem_cnt = text_words->size();
for(int ix=0;ix<elem_cnt;++ix) {
string textword = (*text_words)[ix];
if (textword.size() < 3 ||
exclusion_set.count(textword))
continue;
if (!word_map->count((*text_words)[ix])) {
//loc *ploc = new vector<location,allocator>;
loc *ploc = new vector<location>;
ploc->push_back((*text_locs)[ix]);
word_map->insert(value_type((*text_words)[ix],ploc));
}
else (*word_map)[(*text_words)[ix]]->push_back((*text_locs)[ix]);
}
}

void TextQuery::query_text()
{
string query_text;
do {
cout<<"enter a word against which to search the text.\n"
<<"to quit, enter a single character ==> ";
cin >> query_text;
if (query_text.size() < 2)break;
string caps("ABCDEFGHIJKLMNOPQISTUVWXYZ");
string::size_type pos = 0;
while ((pos = query_text.find_first_of(caps,pos)) != string::npos)
query_text[pos] = tolower(query_text[pos]);
if (!word_map->count(query_text)) {
cout<<"\nSorry. There are no entries for" << query_text <<".\n\n"
continue;
}
loc *ploc = (*word_map)[query_text];
set<short,less<short>,allocator> occurrence_lines;
loc::iterator liter = ploc->begin(),liter_end = ploc->end();
while (liter != liter_end) {
occurrence_lines.insert(occurrence_lines.end(),(*liter).first);
++liter;
}
register int size = occurrence_lines.size();
cout<<"\n"<<query_text<<"occurs"<<size
<<(size == 1 << "time:" : " times:")<<"\n\n";
set<short,less<short>,allocator>::iterator it = occurrence_lines.begin();
for(;it != occurrence_lines.end(); ++it) {
int line = *it;
cout<<"\t(line"<<line+1<<")"<<(*lines_of_text)[line]<<endl;
}
cout<<endl;
}while(!query_text.empty());
cout<<"OK, bye!\n";
}

void TextQuery::display_map_text()
{
typedef map<string,loc*,less<string>,allocator> map_text;
map_text::iterator iter = word_map->begin(),iter_end = word_map->end();

while (iter != iter_end) {
cout<< "word: "<<(*iter).first<<" (";
int loc_cnt = 0;
loc *text_locs = (*iter).second;
loc::iterator liter = text_locs->begin(),liter_end = text_locs->end();
while(liter != liter_end) {
if (loc_cnt)
cout<<",";
else ++loc_cnt;

cout<<"("<<(*liter).first<<","<<(*liter).second<<")";
++liter;
}
cout<<")\n";
++iter;
}
cout<<endl;
}

void TextQuery::display_text_locations()
{
vector<string,allocator> *text_words = text_locations->first;
vector<location,allocator> *text_locs = text_locations->second;
register int elem_cnt = text_words->size();
if (elem_cnt != text_locs->size()) {
cerr<<"oops! internal error: word and position vectors"
<<"are of unequal size \n"
<<"words: "<<elem_cnt<<" "
<<"locs: "<<text_locs->size()
<<"-- bailing out!\n"
exit(-2);
}

for (int ix = 0; ix < elem_cnt; ix++) {
cout<<"word: "<<(*text_words)[ix]<<"\t"
<<"location: ("
<<(*text_locs)[ix].first<<","
<<(*text_locs)[ix].second<<")"
<<"\n";
}
cout<<endl;
}


未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-10 09:46
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 

现在代码只有1处错误:
error C2664: '__thiscall std::istream_iterator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,struct std::char_traits<int> >::std::istream_iterator<class std::basic_str


#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<map>
#include<set>

#include<iostream>
#include<fstream>
using namespace std;

#include<stddef.h>
#include<ctype.h>


typedef pair<short,short>location;
//typedef vector<location,allocator>loc;
typedef vector<location>loc;
//typedef vector<string,allocator>text;
typedef vector<string>text;
typedef pair<text*,loc*>text_loc;

class TextQuery {
public:
TextQuery() { memset(this,0,sizeof(TextQuery)); }
static void filter_elements(string felems) { filt_elems = felems; }
void query_text();
void display_map_text();
void display_text_locations();
void doit() {
retrieve_text();
separate_words();
filter_text();
suffix_text();
strip_caps();
build_word_map();
}
private:
void retrieve_text();
void separate_words();
void filter_text();
void strip_caps();
void suffix_text();
void suffix_s(string&);
void build_word_map();
private:
// vector<string,allocator> *lines_of_text;
vector<string> *lines_of_text;
text_loc *text_locations;
// map<string,loc*,less<string>,allocator> *word_map;
map<string,loc*> *word_map;
static string filt_elems;
};
string TextQuery::filt_elems("\",.;:!<<)(\\/");

int main()
{
TextQuery tq;
tq.doit();
tq.query_text();
tq.display_map_text();

return 0;
}

void TextQuery::retrieve_text()
{
string file_name;
cout << "please enter file name: ";
cin >> file_name;
ifstream infile(file_name.c_str(),ios::in);
if (!infile) {
cerr << "oops! unable to open file"
<< file_name << "--bailing out!\n";
exit(-1);
} else cout << "\n";
// lines_of_text = new vector<string,allocator>;
lines_of_text = new vector<string>;
string textline;
while (getline(infile,textline,'\n'))
lines_of_text->push_back(textline);
}

void TextQuery::separate_words()
{
// vector<string, allocator> *words = new vector<string,allocator>;
vector<string> *words = new vector<string>;
// vector<location,allocator> *locations = new vector<location,allocator>;
vector<location> *locations = new vector<location>;

for (short line_pos = 0; line_pos < lines_of_text->size(); line_pos++) {
short word_pos = 0;
string textline = (*lines_of_text)[line_pos];
string::size_type eol = textline.length();
string::size_type pos = 0,prev_pos = 0;

while ((pos = textline.find_first_of(' ',pos)) != string::npos) {
words->push_back(textline.substr(prev_pos,pos-prev_pos));
locations->push_back(make_pair(line_pos,word_pos));
word_pos++; pos++;prev_pos = pos;
}
words->push_back(textline.substr(prev_pos,pos - prev_pos));
locations->push_back(make_pair(line_pos,word_pos));
}
text_locations = new text_loc(words,locations);
}

void TextQuery::filter_text()
{
if (filt_elems.empty())
return;
// vector<string,allocator> *words = text_locations->first;
vector<string> *words = text_locations->first;
// vector<string,allocator>::iterator iter = words->begin();
vector<string>::iterator iter = words->begin();
// vector<string,alocator>::iterator iter_end = words->end();
vector<string>::iterator iter_end = words->end();

while (iter != iter_end) {
string::size_type pos = 0;
while ((pos = (*iter).find_first_of(filt_elems,pos)) != string::npos)
(*iter).erase(pos,1);
++iter;
}
}

void TextQuery::suffix_text()
{
// vector<string,allocator> *words = text_locations->first;
vector<string> *words = text_locations->first;
// vector<string,allocator>::iterator iter = words->begin();
vector<string>::iterator iter = words->begin();
// vector<string,allocator>::iterator iter_end = words->end();
vector<string>::iterator iter_end = words->end();

while (iter != iter_end) {
if ((*iter).size() <= 3) {
iter++;
continue;
}
if ((*iter)[(*iter).size() -1] = 's')
suffix_s(*iter);
iter++;
}
}

void TextQuery::suffix_s(string &word)
{
string::size_type spos = 0;
string::size_type pos3 = word.size() - 3;
string suffixes("oussisius");

if (!word.compare(pos3,3,suffixes,spos,3) ||
!word.compare(pos3,3,suffixes,spos+6,3) ||
!word.compare(pos3+1,2,suffixes,spos+2,2) ||
!word.compare(pos3+1,2,suffixes,spos+4,2))
return;
string ies("ies");
if (!word.compare(pos3,3,ies)) {
word.replace(pos3,3,1,'y');
return;
}
string ses("ses");
if (!word.compare(pos3,3,ses)) {
word.erase(pos3+1,2);
return;
}
word.erase(pos3+2);

if(word[pos3+1] == '\'')
word.erase(pos3+1);
}

void TextQuery::strip_caps()
{
// vector<string,allocator> *words = text_locations->first;
vector<string> *words = text_locations->first;
// vector<string,allocator>::value_type iter = words->begin();
vector<string>::iterator iter = words->begin();
// vector<string,allocator>::iterator iter_end = words->end();
vector<string>::iterator iter_end = words->end();

string caps("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
while(iter != iter_end) {
string::size_type pos = 0;
while ((pos = (*iter).find_first_of(caps,pos)) != string::npos)
(*iter)[pos] = tolower((*iter)[pos]);
++iter;
}
}


void TextQuery::build_word_map()
{
// word_map = new map<string,loc*,less<string>,allocator>;
word_map = new map<string,loc*>;
// typedef map<string,loc*,less<string>,allocator>::value_type value_type;
typedef map<string,loc*>::value_type value_type;
// typedef set<string,less<string>,allocator>::difference_type diff_type;
typedef set<string>::difference_type diff_type;
//set<string,less<string>,allocator>exclusion_set;
set<string>exclusion_set;
ifstream infile("exclusion_set");

if (!infile) {
static string default_excluded_words[25] = {
"the","and","but","that","then","are","been",
"can","can't","cannot","could","did","for",
"had","have","him","his","her","its","into",
"were","which","when","with","would"
};
cerr<<"warning! unable to open word exclusion file! --"
<<"using default set\n";
copy(default_excluded_words,default_excluded_words+25,
inserter(exclusion_set,exclusion_set.begin()));
} else {
istream_iterator<string,diff_type>
input_set(infile),eos;
copy(input_set,eos,
inserter(exclusion_set,exclusion_set.begin()));
}

// vector<string,allocator> *text_words = text_locations->first;
vector<string> *text_words = text_locations->first;
// vector<location,allocator> *text_locs = text_locations->second;
vector<location> *text_locs = text_locations->second;

register int elem_cnt = text_words->size();
for(int ix=0;ix<elem_cnt;++ix) {
string textword = (*text_words)[ix];
if (textword.size() < 3 ||
exclusion_set.count(textword))
continue;
if (!word_map->count((*text_words)[ix])) {
//loc *ploc = new vector<location,allocator>;
loc *ploc = new vector<location>;
ploc->push_back((*text_locs)[ix]);
word_map->insert(value_type((*text_words)[ix],ploc));
}
else (*word_map)[(*text_words)[ix]]->push_back((*text_locs)[ix]);
}
}

void TextQuery::query_text()
{
string query_text;
do {
cout<<"enter a word against which to search the text.\n"
<<"to quit, enter a single character ==> ";
cin >> query_text;
if (query_text.size() < 2)break;
string caps("ABCDEFGHIJKLMNOPQISTUVWXYZ");
string::size_type pos = 0;
while ((pos = query_text.find_first_of(caps,pos)) != string::npos)
query_text[pos] = tolower(query_text[pos]);
if (!word_map->count(query_text)) {
cout<<"\nSorry. There are no entries for" << query_text <<".\n\n";
continue;
}
loc *ploc = (*word_map)[query_text];
// set<short,less<short>,allocator> occurrence_lines;
set<short> occurrence_lines;
loc::iterator liter = ploc->begin(),liter_end = ploc->end();
while (liter != liter_end) {
occurrence_lines.insert(occurrence_lines.end(),(*liter).first);
++liter;
}
register int size = occurrence_lines.size();
// cout<<"\n"<<query_text<<"occurs"<<size
// <<(size == 1)<< "time:" : " times:"<<"\n\n";
cout<<"\n"<<query_text<<"occurs"<<size
<<"\n\n";
// set<short,less<short>,allocator>::iterator it = occurrence_lines.begin();
set<short>::iterator it = occurrence_lines.begin();
for(;it != occurrence_lines.end(); ++it) {
int line = *it;
cout<<"\t(line"<<line+1<<")"<<(*lines_of_text)[line]<<endl;
}
cout<<endl;
}while(!query_text.empty());
cout<<"OK, bye!\n";
}

void TextQuery::display_map_text()
{
// typedef map<string,loc*,less<string>,allocator> map_text;
typedef map<string,loc*> map_text;
map_text::iterator iter = word_map->begin(),iter_end = word_map->end();

while (iter != iter_end) {
cout<< "word: "<<(*iter).first<<" (";
int loc_cnt = 0;
loc *text_locs = (*iter).second;
loc::iterator liter = text_locs->begin(),liter_end = text_locs->end();
while(liter != liter_end) {
if (loc_cnt)
cout<<",";
else ++loc_cnt;

cout<<"("<<(*liter).first<<","<<(*liter).second<<")";
++liter;
}
cout<<")\n";
++iter;
}
cout<<endl;
}

void TextQuery::display_text_locations()
{
// vector<string,allocator> *text_words = text_locations->first;
vector<string> *text_words = text_locations->first;
// vector<location,allocator> *text_locs = text_locations->second;
vector<location> *text_locs = text_locations->second;
register int elem_cnt = text_words->size();
if (elem_cnt != text_locs->size()) {
cerr<<"oops! internal error: word and position vectors"
<<"are of unequal size \n"
<<"words: "<<elem_cnt<<" "
<<"locs: "<<text_locs->size()
<<"-- bailing out!\n";
exit(-2);
}

for (int ix = 0; ix < elem_cnt; ix++) {
cout<<"word: "<<(*text_words)[ix]<<"\t"
<<"location: ("
<<(*text_locs)[ix].first<<","
<<(*text_locs)[ix].second<<")"
<<"\n";
}
cout<<endl;
}


未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-10 10:25
olivezhang
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-9-14
收藏
得分:0 
1. istream_iterator<string, diff_type>使用不当。
类istream_iterator带四个参数(如下示),其中后三为默认参数,参数应由左向右逐个使用。
template <
class Type
class CharType = char
class Traits = char_traits<CharType>
class Distance= ptrdiff_t
>
2. input_set(infile),eos;中,input_set和eos没有声明





谷底深深行 ,峰顶漫漫步......@_@
2006-03-10 10:42
快速回复:[求助] 编译无法通过
数据加载中...
 
   



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

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