Home » Community » Newbie corner » From std::string to String
Re: From std::string to String [message #49470 is a reply to message #49468] |
Thu, 15 February 2018 16:03 |
Oblivion
Messages: 1093 Registered: August 2007
|
Senior Contributor |
|
|
Hello Giorgio
[It seems Omari has already replied. ]
Quote:
I use LoadFile() and noticed that is has no .close() method or something like that (it replaces a ifstream in c++ standard library and with it I have to open and close the file): my understanding is that I have not to open/close the stream as with ifstream; is my understanding correct?
No, you don't. LoadFile() is a function, it does not have any method. It reads a file into a string, and closes the file/stream automatically.
If you need control over the stream, you can use FileIn, FileOut, FileAppend classes. (In fact, LoadFile() function uses an instance of FileIn)
They'll be closed automatically when they get out of their scope (when they are destroyed). In between you can explicity call Close() if you need to.
Previously, I used std::vector<std::string> and the application compiled, but now I get "error C2280: attempting to reference a deleted function".
Probably because of move/copy semantics. Something is destroyed in the process, before it can be referenced. chech if your data can be copied or moved.
As far as I can see, you are passing a copy of vector, just put an ampersand (&)
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Thu, 15 February 2018 16:06] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed May 08 04:45:20 CEST 2024
Total time taken to generate the page: 0.03301 seconds
|