string类问题求助

saltyfisher 2015-03-29 05:57:20

class Text_Editor
{
private:
typedef vector<string> Line;
typedef vector<Line> Page;
typedef vector<Page> Text;
string content;
int page_count;
int line_count;
public:
Line line;
Page page;
Text text;
public:
Text_Editor();
Text_Editor(string&);
Text_Editor(ifstream&);
bool sort();
bool destroy();
void retrive();
friend string::iterator &Goto(Text_Editor&, int, int, int);
string::iterator &insert(string::iterator&, string::iterator&, string::iterator&);
string::iterator &erase(string::iterator&, string::iterator&);
string::iterator &erase(string::iterator&);
string ©s(string::iterator&, string::iterator&);
string::iterator &paste(string::iterator&, string::iterator&, string::iterator&, string::iterator&);
friend std::ostream& operator<<(std::ostream&, Text_Editor&);
};
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();
}
string::iterator &Goto(Text_Editor &te, int npage, int nline, int nstr)
{
int len = 0;
for (Text_Editor::Text::iterator ttemp = te.text.begin(); ttemp < te.text.begin() + npage; ttemp++)
{
if (ttemp != te.text.begin() + npage)
{
for (Text_Editor::Page::iterator ptemp = ttemp->begin(); ptemp != ttemp->end(); ptemp++)
{
Text_Editor::Line::iterator ltemp = ptemp->begin();
string stemp(ltemp->begin(), ltemp->end());
len += stemp.size();
}
}
else
{
for (Text_Editor::Page::iterator ptemp = ttemp->begin(); ptemp < ttemp->begin() + nline; ptemp++)
{
if (ptemp != ttemp->begin() + nline)
{
Text_Editor::Line::iterator ltemp = ptemp->begin();
string stemp(ltemp->begin(), ltemp->end());
len += stemp.size();
}
else
len += nstr;
}
}
}
return te.content.begin() + len;
}
string::iterator &Text_Editor::insert(string::iterator& pos, string::iterator& str_begin, string::iterator& str_end)
{
pos = content.insert(pos, str_begin, str_end);
content.begin();
content.end();
sort();
return pos;
}
string::iterator &Text_Editor::erase(string::iterator& begin, string::iterator& end)
{
end = content.erase(begin, end);
content.end();
sort();
return end;
}
string::iterator &Text_Editor::erase(string::iterator& str)
{
str = content.erase(str);
content.end();
sort();
return str;
}
string &Text_Editor::copys(string::iterator& begin, string::iterator& end)
{
return string(begin, end);
}
string::iterator &Text_Editor::paste(string::iterator& str_begin, string::iterator& str_end, string::iterator& begin, 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 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)
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)
实在找不出来,请各位帮忙!
...全文
123 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
saltyfisher 2015-03-29
  • 打赏
  • 举报
回复
引用 3 楼 jiht594 的回复:
删代码, 一个函数一个函数试吧, 看看到底哪句出问题了
问题找到了,多谢提醒!
jiht594 2015-03-29
  • 打赏
  • 举报
回复
删代码, 一个函数一个函数试吧, 看看到底哪句出问题了
saltyfisher 2015-03-29
  • 打赏
  • 举报
回复
引用 1 楼 zhangxiangDavaid 的回复:
你双击错误提示,看看错在哪一行?
双击之后会进到一个xstring文件里 _TRY_BEGIN for (; _First != _Last; ++_First) append((size_type)1, (_Elem)*_First); _CATCH_ALL _Tidy(true); _RERAISE; _CATCH_END
苏叔叔 2015-03-29
  • 打赏
  • 举报
回复
你双击错误提示,看看错在哪一行?

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧