开发者

Qstring replace is not working fine

i want to replace temp.replace

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

Here i am getting error error C2001: newline in constant

error C2275: 'QString' : illegal use of this type as an expression

How can i replace "/" with "\"


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

// 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\*.*



S开发者_JAVA百科HFILEOPSTRUCT 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\*.*

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


By escaping it with another \:

"\\"

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.


The help below is for Qt4 library!

If you need to normalize file absolute path you may use for you needs toNativeSeparators function. Here is the Qt Assistant information about it:

QString QDir::toNativeSeparators ( const QString & pathName ) [static] Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32".

The returned string may be the same as the argument on some operating systems, for example on Unix.

This function was introduced in Qt 4.2.

See also fromNativeSeparators() and separator().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜