Closed L-Super closed 2 weeks ago
When the string is large, iterating and assigning values becomes inefficient.
std::string data{"word"}; try { mio::mmap_sink mmap(path, 10); for (int i = 0; i < data.size(); ++i) { mmap[i] = data[i]; } } catch (std::system_error e) { std::cout<<"error: "<<e.what()<<"\n"; }
memcpy(&mmap[0], data.cstr(), data.size)
Thanks! I found that std::copy is also a good way.
std::copy
When the string is large, iterating and assigning values becomes inefficient.