简体   繁体   中英

how to convert String in arduino library to std::string in c++

I have problem converting a String to std::string, to pass it to my function as the sample of my code is

String dataString = configFile.readString();
rawData = simplifyData("try to fetch data as string from dataString");

Since std::string has a constructor accepting a const char* as parameter you can copy your String by using this, eg:

rawData = simplifyData(std::string(dataString.c_str()));

Or, since this constructor is implict, you can simplify it in your function call, such as

rawData = simplifyData(dataString.c_str());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM