我处理文件以及与每个节点线看起来像这样的链接列表:std :: out_of_range错误?
struct TextLine{
//The actual text
string text;
//The line number of the document
int line_num;
//A pointer to the next line
TextLine * next;
};
,我正在写一个函数,在线路中的变量text
发现开头添加空格,通过调用像linelist_ptr->text.insert(0,1,'\t');
的程序编译,但是当我运行它,我得到这个错误的功能:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at
Aborted
任何想法?
您没有提供足够的信息。你所提供的代码不能以你描述的方式失败,所以也许其他一些代码失败了,你还没有放在这里。 – Omnifarious 2010-05-27 03:33:54
任何你不使用'std :: list'的原因? (家庭作业?)甚至更好,'std :: vector'或'std :: deque'。 – GManNickG 2010-05-27 03:39:53
你可以请检查一下你的实现是否使用'char *'作为'string :: iterator'?你可以做'#include',然后'std :: cout << typeid(std :: string :: iterator).name()' - 并告诉结果。 –
2010-05-27 03:51:57