与换行Windows C ++比较 [英] Compare to newline windows C++

查看:68
本文介绍了与换行Windows C ++比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的代码:

string isNewline(string text)
{   
    string toReturn;
    text == "\r\n" ? toReturn = "(newline)" : toReturn = text;
    return toReturn;
}

此函数从不返回(换行符)字符串,所以我猜测我与换行符的比较是错误的。我该如何纠正?

this function never returns a "(newline)" string, so I'm guessing that my comparison with newline character is wrong. How can I correct this?

PS。 Windows函数

PS. Windows function

推荐答案

您的 isNewline 函数没有问题。

问题是如何将字符串传递给 isNewline 函数。

The problem is how you get the string to be passed to isNewline function.

我怀疑您使用了类似 getline(fin,aLine)之类的字符串来获取如下字符串?

I suspect you use something like getline(fin,aLine) to get the string like below?

while(getline(fin,aLine)){
   cout<<aLine<<endl; //aLine will never contain newline character because getline never save it
   cout<<isNewline(aLine)<<endl; // so this will never output "(newline)"
}

getline 不会将换行符保存到 aLine

getline does not save the newline character into aLine

这篇关于与换行Windows C ++比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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