我有一个使用g ++编译器在Linux上运行的简单程序:
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char **argv){
fstream file;
string s;
file.open("sample/dates.dat", fstream::in);
if(!file.good())
return 0;
getline(file, s);
cout << s << "." << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译:g++ -o test test.cpp.当我运行它时,在字符串s之前打印fullstop,而不是之后.有人知道为什么会这样吗?它很容易修复吗?
谢谢.
如果字符串末尾有回车符,则在打印时会将输出位置移动到控制台行的开头.
#include <iostream>
int main()
{
std::cout << "some line\r" << "." << std::endl;
// ^^ carriage return
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1279 次 |
| 最近记录: |