Pregunta

I would like to find the tab character in a wstring.

However

int n =mywstring.find(L"\t");

does not work, "n" is -1, although I know that the tab character is present in the wstring.

What am I missing here?

Thank you for the help!

Edit:

I found that the problem lies in the way I read the wstring from the file.

I am using

bool GetLineW(FILE *inFile, wstring &result)
{
wchar_t data[2]={0,0};

result = L"";
do{
    fread(data, sizeof(wchar_t), 1, inFile);

    if (data[0]>=L' ')
        result += data;

    if (data[0]==0x0A)
        break;
}while(!feof(inFile));

if (result.size()>0)
    return true;
else
    return false;
}
¿Fue útil?

Solución

wstring::find and string::find returns npos in case the character is not found, which is equivalent to -1.

A return value of 0 means that the character has been found at the first index of the string, since indexes start at 0.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top