From d83047abec1187f9d6762a1c6c34592812a81b2c Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 21 May 2022 20:35:54 +0200 Subject: [PATCH] Updated Frequently asked Questions for using Raylib with C Plus Plus (markdown) --- ...tions-for-using-Raylib-with-C-Plus-Plus.md | 18 ------------- How-To:-Using-raylib-with-C--.md | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) delete mode 100644 Frequently-asked-Questions-for-using-Raylib-with-C-Plus-Plus.md create mode 100644 How-To:-Using-raylib-with-C--.md diff --git a/Frequently-asked-Questions-for-using-Raylib-with-C-Plus-Plus.md b/Frequently-asked-Questions-for-using-Raylib-with-C-Plus-Plus.md deleted file mode 100644 index d0b7fcb..0000000 --- a/Frequently-asked-Questions-for-using-Raylib-with-C-Plus-Plus.md +++ /dev/null @@ -1,18 +0,0 @@ -This page will go over some of the common questions new users of Raylib have when using C++. - -# How do I use Raylib with C++? - -Raylib works with C++ in the exact same way it does with the C language. You can use Raylib from C++ with no special modifications or build steps. Simply include Raylib for your compiler and platform in the exact same way you do for C. Raylib is fully compatible with both C and C++. - -# Do I have to use Raylib-CPP to use Raylib with C++? - -No, Raylib-CPP is not required to use Raylib with C++. Raylib-CPP is an optional wrapper that sits on top of the regular C Raylib in order to provide object oriented access to Raylib. Raylib-cpp still calls the same C Raylib in the end. - -# I Get an error on code like this 'a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax' when building an example in C++ `(Vector3){1.0f,2.0f,3.0f}`. How Can I fix it? - -This type of structure initialization `(Vector3){1.0f,2.0f,3.0f}` is called a compound literal and is not supported by C++. Some C++ compilers are strict and will not allow it. This code can be converted to brace initialization in C++ by simply removing the parentheses around the type. Changing the code to `Vector3{1.0f,2.0f,3.0f}` will fix the error. This change needs to be made for code that is pulled from the Raylib C examples. - -# DrawText takes a const char*, but I have a std::string, how can I draw my string? - -std::string has a method named c_str(), this will return the const char* stored in the string, use it as the argument for any C function that takes a const char*. -`DrawText(my_string.c_str(),0,0,20,RED);` diff --git a/How-To:-Using-raylib-with-C--.md b/How-To:-Using-raylib-with-C--.md new file mode 100644 index 0000000..6460fa0 --- /dev/null +++ b/How-To:-Using-raylib-with-C--.md @@ -0,0 +1,27 @@ +This page will go over some of the common questions new users of raylib have when using C++. + +# How do I use raylib with C++? + +raylib works with C++ in the exact same way it does with the C language. You can use raylib from C++ with no special modifications or build steps. Simply include raylib for your compiler and platform in the exact same way you do for C. raylib is fully compatible with both C and C++. + +# Do I have to use `raylib-cpp` to use raylib with C++? + +No, `raylib-cpp` is not required to use raylib with C++. `raylib-cpp` is an optional wrapper that sits on top of the regular C raylib in order to provide object oriented access to raylib. `raylib-cpp` still calls the same C raylib in the end. + +# How can I fix C [compound-literals](https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html) related errors? + +You can get the folllowing error when building raylib examples in C++ in C++: + + > `A parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax` + +This type of structure initialization `(Vector3){ 1.0f, 2.0f, 3.0f }` is called a compound literal and is not supported by C++. Some C++ compilers are strict and will not allow it. This code can be converted to brace initialization in C++ by simply removing the parentheses around the type. Changing the code to `Vector3{ 1.0f, 2.0f, 3.0f }` will fix the error. + +This change needs to be made for code that is pulled from the raylib C examples. + +# How can I draw my string? + +`DrawText()` takes a `const char *text`, but I have a `std::string` in C++; `std::string` has a method named `c_str()`, this will return the `const char *str` stored in the string, use it as the argument for any C function that takes a `const char *text`. Example: + +```cpp +DrawText(my_string.c_str(),0,0,20,RED); +```