将endline插入字符串流 [英] Inserting endline into a stringstream

查看:153
本文介绍了将endline插入字符串流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,当在文件流中插入 \\\
时,系统的相应行结束序列将被写入文件(例如 \r\\\
Windows)。在 std :: stringstream 中插入一个结束行是否会导致系统适当的行结束序列被写入字符串?例如:

We know that when inserting \n in a file stream, the appropriate end-of-line sequence for the system will be written to the file (e.g. \r\n for Windows). Does inserting an endline in a std::stringstream result in the system-appropriate end-of-line sequence being written to the string? For example:

#include <sstream>

int main()
{
    std::ostringstream oss;
    oss << std::endl;
    std::string endlineSequence = oss.str();
    bool isWindows = enlineSequence == "\r\n";
    bool isOldMac  = endlineSequence == "\r";
    bool isUnix    = endlineSequence == "\n";
    // Will this work???
}


推荐答案

系统特定行尾仅与文本文件相关。只要流只在内存中,它只是'\\\
'

The system specific line endings are only relevant for text files. As long as the stream is only in memory, it is just '\n'.

这篇关于将endline插入字符串流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆