#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)

west oasis
#

I'm making a hex identifier for a password embedder program that i'm making, and i was wondering if you could review the library i'm making for the hex identifier

fierce steppeBOT
# west oasis
Compiler Output
<source>:3:10: fatal error: string: No such file or directory
    3 | #include <string>
      |          ^~~~~~~~
compilation terminated.
Build failed
steady prairie
#

using namespace std in a header isn't a good idea

west oasis
#

then what should i use?

#

should i use the traditional std:: method?

steady prairie
#

yes definitely

west oasis
#

okay, thanks

#

here it is now

steady prairie
#

very cool 👍

west oasis
#

thank you

steady prairie
west oasis
#

i wonder

steady prairie
#

actually hold on let me test something

west oasis
steady prairie
#

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

lunar stream
#

@west oasis Are these just ascii codes in hex?

#

I wouldn't make named string constants for these

west oasis
#

i was kinda worrying about putting them to strings

lunar stream
#
std::string ascii_to_hex(char c) {
    std::stringstream ss;
    ss<<std::hex<<int(c);
    return std::move(ss.str());
}
```should do it
west oasis
#

all of that?

#

so what does it do?

lunar stream
#

ascii_to_hex

west oasis
#

so it converts ascii symbols to hexadecimal?

west oasis
#

thanks guys
!close

#

!close

#

hmm...

foggy geode
#

or can rvo not kickin because youre using the .str method

#

yea it does

#

std::stringstream::str returns a new string

lunar stream
#

@orchid nest has a good explanation for this

#

but I forget what it was

foggy geode
#

return std move rvo stuff is hard

#

ill wait for him to explain it

orchid nest
#

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();
}

lunar stream
frank fern
#

is there anything similar pre C++20?

#

because i mostly use C++17

orchid nest
#

yes, there's no way of doing this pre-C++20

#

But simultaneously, doing this has no harm in C++17 either, and you get free perf improvements if you move to C++20