尝试如下:
include <iostream>
using std::cout;
int main(){
cout << "before seekp:";
cout.seekp(-1, ios::cur) << std::endl;
cout << "keep printing.\n";
}
gdb会跑完不报错,但是除了第一个cout其他的均未打印出。
想请教下这是什么原因,多谢!
第一行不报错么,还有ios的命名空间也没引用吧
#include <iostream>
using namespace std;
int main(){
cout << "before seekp:";
cout.seekp(-1, ios::cur) << std::endl;
cout << "keep printing.\n";
}
输出:
before seekp
keep printing.
如果要保留冒号,seekp(0,ios::cur)
望采纳。
已在知乎有解答