首页 新闻 会员 周边

使用string遇到的问题

0
悬赏园豆:10 [已关闭问题] 关闭于 2015-04-01 18:11

typedef vector<string> Line;
typedef vector<Line> Page;
typedef vector<Page> Text;
string content;
Line line;
Page page;
Text text;




Text_Editor::Text_Editor() { line_count
= page_count = 0; } Text_Editor::Text_Editor(string &s) { line_count = page_count = 0; swap(content,s); sort(); } Text_Editor::Text_Editor(ifstream &fin) { while (getline(fin, content)); sort(); } bool Text_Editor::sort() { int i = 0; int j = 0; if (!text.empty()) text.clear(); auto temp_begin = content.begin(); auto temp_end = content.begin(); for (; j < content.size(); j++) { if (content[j] == '\n' || j%70 == 0||content.size()-j==0) { line_count++; temp_end += j; string stemp(temp_begin, temp_end); line.push_back(stemp); page.push_back(line); temp_begin += stemp.size(); stemp.clear(); line.clear(); temp_end = content.begin(); i++; if (i % 20 == 0||j==content.size()) { page_count++; text.push_back(page); page.clear(); } } } return true; } bool Text_Editor::destroy() { text.clear(); } const string::iterator &Text_Editor::Goto(int npage, int nline, int nstr) { int len = 0; for (Text::iterator ttemp = text.begin(); ttemp < text.begin() + npage; ttemp++) { if (ttemp != text.begin() + npage) { for (Page::iterator ptemp = ttemp->begin(); ptemp != ttemp->end(); ptemp++) { Line::iterator ltemp = ptemp->begin(); string stemp(ltemp->begin(), ltemp->end()); len+=ltemp->size(); } } else { for (Page::iterator ptemp = ttemp->begin(); ptemp < ttemp->begin() + nline; ptemp++) { if (ptemp != ttemp->begin() + nline) { Line::iterator ltemp = ptemp->begin(); len += ltemp->size(); } else len += nstr; } } } return content.begin()+len; } const string::iterator &Text_Editor::insert(string::iterator& pos, const string::iterator& str_begin, const string::iterator& str_end) { pos = content.insert(pos, str_begin, str_end); content.begin(); content.end(); sort(); return pos; } const string::iterator &Text_Editor::erase(const string::iterator& begin, string::iterator& end) { end = content.erase(begin, end); content.end(); sort(); return end; } const string::iterator &Text_Editor::erase(string::iterator& str) { str = content.erase(str); content.end(); sort(); return str; } const string &Text_Editor::copys(const string::iterator& begin, const string::iterator& end) { return string(begin, end); } const string::iterator &Text_Editor::paste(const string::iterator& str_begin, const string::iterator& str_end, string::iterator& begin, const string::iterator& end) { begin = content.insert(content.erase(begin, end), str_begin, str_end); content.begin(); content.end(); sort(); return begin; } std::ostream &operator<<(std::ostream &os, Text_Editor &te) { int page_count = 0; int line_count = 0; for (auto ptemp = te.text.begin(); ptemp != te.text.end(); ptemp++) { for (auto ltemp = ptemp->begin(); ltemp != ptemp->end(); ltemp++) { string temp(ltemp->begin(), ltemp->end()); os << temp; line_count++; } page_count++; os << page_count << "page " << line_count << "line" << endl; } return os; }

编译的时候出现

Error 5 error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::append(std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>,std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>)' : cannot convert argument 1 from 'unsigned int' to 'std::initializer_list<_Elem>' f:\program files (x86)\microsoft visual studio 12.0\vc\include\xstring 850 1 Text_Editor(Edition2)

Error 4 error C2440: 'type cast' : cannot convert from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'char' f:\program files (x86)\microsoft visual studio 12.0\vc\include\xstring 850 1 Text_Editor(Edition2)

实在找不出问题,求帮忙,多谢!

C++
saltyfish的主页 saltyfish | 菜鸟二级 | 园豆:202
提问于:2015-03-26 22:07
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册