#I'm kinda new to C++ and making .h files, so I was wondering if you could try out my library
50 messages · Page 1 of 1 (latest)
<source>:3:10: fatal error: string: No such file or directory
3 | #include <string>
| ^~~~~~~~
compilation terminated.
Build failed
using namespace std in a header isn't a good idea
yes definitely
very cool 👍
thank you
do you know why this is?
i wonder
actually hold on let me test something
heres the new one
so
if i include your header, i would also have using namespace std; in my code now
#include "hzHEXstd.h"
#include <algorithm>
int main() {
min(1, 3); // available without std:: prefix even though it's after the `using namespace std;` thing
}
and then naming conflicts
at least thats as far as i know
@west oasis Are these just ascii codes in hex?
I wouldn't make named string constants for these
these are ascii to hex, yes
i was kinda worrying about putting them to strings
std::string ascii_to_hex(char c) {
std::stringstream ss;
ss<<std::hex<<int(c);
return std::move(ss.str());
}
```should do it
ascii_to_hex
so it converts ascii symbols to hexadecimal?
Doesn't this return std::move prevent RVO?
or can rvo not kickin because youre using the .str method
yea it does
std::stringstream::str returns a new string
Should be return std::move(ss).str();
This will cause it to choose the rvalue overload, which means that str() will move out of ss's underlying buffer rather than copying
equivalently, doing ```cpp
std::string ascii_to_hex(char c) {
return (std::ostringstream{} << std::hex << (int)c).str();
}
Oh, right 🙂
but isnt this only since C++20?
is there anything similar pre C++20?
because i mostly use C++17