Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C++
std::string f;
f.append(0,2);
f[0]=2;
f[1]=1;
//f="cd";

std::string s;
s.append(0,5);
s[0]=1;
s[1]=2;
s[2]=1;
s[3]=3;
s[4]=1;
//s="abcde";

unsigned int pp=0;
pp=s.find(f);


this code work fine in Visual Studio 2008 sp1,operation system is Win7 64Bit sp1

but in C++ Builder XE10.2,function "find" always return "npos"
if change strings with normal charactors,like "abcdef","cde",it's work well

How can I make std::string::find work fine in C++ Builder XE10.2 ???

What I have tried:

C++
std::string f;
//f.append(0,2);
//f[0]=2;
//f[1]=1;
f="cd";

std::string s;
//s.append(0,5);
//s[0]=1;
//s[1]=2;
//s[2]=1;
//s[3]=3;
//s[4]=1;
s="abcde";

unsigned int pp=0;
pp=s.find(f);


change std::string with normal charactors work fine
Posted
Updated 7-Dec-17 20:42pm

I think you could write :
C++
f[0] = 'c';
f[1] = 'd';

or
C++
f[0] = 'a' + 2;
f[1] = 'a' + 3;
 
Share this answer
 
the std:string not only use for charactors,in fact it can store data like BYTE each element.
so ,why "abcde" work,but "0x1,0x2,0x3" not work ??

and these code work in Visual Studio 2008 fine.....
 
Share this answer
 
OK,someone told me a solution

change "f.append(0,2); s.append(0,5)" to "f.resize(2); s.resize(5)" then it's work fine!!
 
Share this answer
 
C++
s.append(0,5) //wrong
s.append(5,0) //right


sorry for waste your time......
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900