Skip to content

Instantly share code, notes, and snippets.

@Adobe-Android
Last active September 17, 2020 18:10
Show Gist options
  • Save Adobe-Android/39b11cac418e03a521aeea862ac6e69e to your computer and use it in GitHub Desktop.
Save Adobe-Android/39b11cac418e03a521aeea862ac6e69e to your computer and use it in GitHub Desktop.
A small modern C++ example converting a std::string to a c-style string (character array).
#include <iostream>
#include <string>
void print_to_screen(const char* char_array) { std::cout << char_array << '\n'; }
int main() {
std::string std_str{"Hello, World!\n"};
const char* char_array{std_str.c_str()};
print_to_screen(char_array);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment