Qstring 替换无法正常工作 [英] Qstring replace is not working fine

查看:61
本文介绍了Qstring 替换无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想替换 temp.replace

i want to replace temp.replace

(QString("/"), QString("\"));

这里出现错误错误 C2001:常量中的换行符
错误 C2275:QString":非法使用此类型作为表达式

Here i am getting error error C2001: newline in constant
error C2275: 'QString' : illegal use of this type as an expression

如何用\"替换/"

感谢 4 你的回答.但直到现在我还没有对我的问题进行排序.请检查我的代码

thakns 4 ur answer. But till now i didnt sort my issue. Please check my code

//转换为 wchar_t*

// Convert to a wchar_t*

size_t origsize = strlen(toChar) + 1;

const size_t newsize = 100;

size_t convertedChars = 0;

wchar_t wcstring[newsize];

mbstowcs_s(&convertedChars, wcstring, origsize, toChar, _TRUNCATE);

wcscat_s(wcstring, L"\\*.*\0");

wcout << wcstring << endl; // C:\Documents and Settings\softnotions\Desktop\Release\*.*



SHFILEOPSTRUCT sf;

memset(&sf,0,sizeof(sf));

sf.hwnd = 0;

sf.wFunc = FO_COPY;

 //sf.pFrom =wcstring;  /* when giving wcstring i am not getting answer */

  sf.pFrom = L"C:\\Documents and Settings\\softnotions\\Desktop\\Release\\*.*\0";

   wcout << sf.pFrom  <<endl;   // C:\Documents and      Settings\softnotions\Desktop\Release\*.*

wcstring 和 sf.pFrom 都是相同的,那么在分配 sf.pFrom =wcstring 时不会得到答案;

Both wcstring and sf.pFrom are same then y not gettng answer when assigning sf.pFrom =wcstring;

推荐答案

通过使用另一个 \ 对其进行转义:

By escaping it with another \:

"\\"

这是关于转义如何在字符串中工作的一般 C/C++ 问题.由于 \ 用于转义,因此在字符串中具有特殊含义,因此应该对其本身进行转义.

This is a general C/C++ gotcha about how escaping works inside character strings. Since \ is used for escaping and thus has a special meaning inside a string, it should be escaped itself.

编译器抛出的错误是它看到第二个字符串常量一直到行尾,因为 \" 阻止它结束字符串.

The error thrown by your compiler is that it sees the second string constant going until the end of the line, since \" precludes it from ending the string.

这篇关于Qstring 替换无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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