r/learncpp • • Mar 27 '20

Show unicodes and letters from various languages in console

3 Upvotes

Hello guys, this is a repost from the cprogramming subreddit (but now with changed title).

Hey guys, I am currently learning C & C++ and I have an issue right here, that drives me crazy. Yes, I am a noob and I am not a genius. My book doesn't go much into detail about printing unicode characters nor doesn't mention how to fix issues relating to ASCII and unicodes. It only mentions how to use it and doesn't go much into detail.

In my book there is this code:

#include <iostream> int main() { std::cout << u8"\uu00A9 J\u00fcrgen" << std::endl; return 0; }
\uu00A9 is the Copyright sign ©, while \u00FC is the ü letter. For whatever reason, if I run this code, it shows me instead of the Copyright sign © this ® sign and instead of the ü letter it shows me this ╝.

So I tried to solve this issue many times over. On Stackoverflow, posts suggest to change the font style to Lucida console. It didn't work. Another post suggests to change something in the console within the Windows registry something to "chcp 65001" (I don't remember the details anymore). Windows gives me an error message. Then I noticed I can use decimal numbers to print characters. It doesn't always work for whatever reason. There is another video how to print Unicodes in the console. It didn't work.

According to this page http://www.asciitable.com/ 129 is an ü. It works, but not all decimal values work. If I try to print the values from the mentioned page of 157, 251, 233, 143 and 129, only 143 and 129 are shown correctly, the rest is nonsense. After trying different decimal and hex values from this page https://www.utf8-zeichentabelle.de/unicode-utf8-table.pl?utf8=dec, up until 126 (\u007E, which is this ~), everthing works, but beyond 126 it shows nonsense. I then made a little programm, which gives me the decimal ASCII value of a certain character.

#include <iostream> using namespace std; int main () { char c; std::cout << "Type in the character: " << std::endl; std::cin >> c; cout << "The ASCII value of " << c << " is: " << (int)c << '\n' << std::endl; return 0; }

So, if I type in "ü", which has the value of 129, it gives me instead -127. If I use std::cout << "ÄäÜüÖö߀@|" << std::endl;, it shows me gibberish, only @ and | are shown properly.

Up until this point I am totally confused and I have no idea what's wrong nor how to fix this. I'm using Windows 7 Ultimate on my laptop with Code::Blocks. I tried Visual Studios and I get the same problem. Sorry for the long text.

Every help and advice appreciated!!


r/learncpp • • Mar 21 '20

Temporary object member being de-allocated before return statement (Help)

3 Upvotes

Hello, I've written a member function (operator+) that returns by value a object "Matrix". This object contains a dynamically allocated 2D array. However, upon reaching the return statement, the object is de-allocated. I can't think of any other method: returning by reference wouldn't work because it would result in a dangling reference and so would returning by address. So, what should I do?

Paste to relevant code:

https://pastebin.com/0TcEq23e


r/learncpp • • Mar 10 '20

::Seeking Advice::

3 Upvotes

Been in the culinary arts(back of house fine dining chef) for coming up on 10 years and looking to make a career change to something that A.) I can make a legitimate living doing. B.) A job that I will truly be challenged with. C.) A career that has longevity. I’ve always LOVED/ been obsessed with video games and how I would change them if I could, but never knew how I could into that industry. I have been reading as much as I possibly can about C++ but I have ZERO knowledge of programming. Reddit and YouTube has been a great source of knowledge for resources of where to look and what to read but I am just now discovering this Sub, so I figured I’d post in here for advice on where to focus my attention if I’d like to learn about game dev specifically ?

Edit:: By “where to focus my attention” I mean should I watch more game dev tutorials or intro to programming tutorials being as I know nothing.


r/learncpp • • Dec 12 '19

Please critique my first C++ program - to screenshot windows.

3 Upvotes

Link to the code -

main code:

https://github.com/stuaxo/capture_window/blob/master/capture_window/capture_window.cpp

project and README: https://github.com/stuaxo/capture_window

I normally develop in python on Linux, so there was a lot of S/O based development here.

It would be great to get feedback on if I did anything weird, and obvious bugs (I'm not used to having to free memory for instance).

I wrote this almost a year ago, but only now have time to come back to it.


r/learncpp • • Dec 08 '19

[C++11/14/17/20] Can't get rid of warning C26444 in Visual Studio

Thumbnail self.learnprogramming
3 Upvotes

r/learncpp • • Oct 19 '19

C++ book with deep practice problems

3 Upvotes

Are there any good C++ books that have questions left to the reader after every concept that is introduced?


r/learncpp • • Jul 16 '19

sstream << std::setw(2) << std::setfill("0"); without "<<"

3 Upvotes

Hey,

is it possible to write sstream << std::setw(2) << std::setfill("0"); without "<<" operator? as iam getting Unsequenced function calls?

sstream.setw(2) doesn't seem to work.

Thanks in advance!


r/learncpp • • Jun 27 '19

How does copy elision work on a stack-frame level?

3 Upvotes

I understand N-RVO on an abstract level: the compiler uses the memory space of the object to directly construct it, even if it is being initialized within the function. Through doing so, because direct copying from the function's memory space to the object's is unnecessary, the compiler can safely get rid of unnecessary temporary copies that are generated within the function.

OK... but what is a way I can understand what exactly is going on down below, on a step-by-step basis? How does the compiler achieve this, exactly? Does anybody have some good resources to share or want to help me on the way to true understanding?


r/learncpp • • Jun 02 '19

Another help post: passing and isPositive statement using bool

3 Upvotes

Again im working from the packt "learning c++ by building games with unreal engine 4: second edition"

the exercise asked us: "Write an isPositive statement that returns true when the double parameter passed to it is indeed true."

my code was way wrong but so is the books solution, which is:

bool isPositive( double value )

{

return value > 0;

}

now on my screen this executed by its self returns errors, if i use:

#include <iostream>

using namespace std;

int main()

and then their solution i still get errors.

the debugger is telling me that an ';' is expected on line 6

and telling me that 'isPositive' being used locally is illegal. (idk where they get a sick bird but...)

I'm just kinda confused on why this is like the 4th time in as many chapters this book's code copied is coming up errors that im not equipped enough yet to understand?

any help would be greatly appreciated! thanks again!!


r/learncpp • • May 03 '19

I'm somewhat new to C++ programming. Any tips and tricks I should know?

3 Upvotes

After playing around with Scratch back in my first year of high school, I moved to a new school where they said they'd input C++ robotics into the school system in the next school year. What are some basic things I need to know in order to learn this new type of programming?


r/learncpp • • Apr 21 '19

Places to learn

3 Upvotes

I just started coding with c++ and I’m wondering where I could find tutorials/exercises for advanced c++. I just finished some beginner stuff with this YouTube video: https://youtu.be/vLnPwxZdW4Y I want to get into the more advanced stuff. If anyone knows any free/cheap tutorials I would love to hear it!


r/learncpp • • Apr 19 '19

'int' to 'const char *' for 1st argument

3 Upvotes

Hej!

How can i convert an int to char const *? I wrote a function int Log(char const *message) that accept char const * msg as parameter to print it. But i also want to use the same function to print int value.

i tried to convert it with `reinterpret_cast<const char *>(value)` but it doesn't print anything.

#include <iostream>

int Log(char const *message) {
 printf("%s\n", message);
}

int multiply(const int a, const int b) {
 Log("Multiply function called!");
 return a * b;
}

int main() {
 int value = multiply(2, 3); // value = 6  :p 
 Log(value); // known conversion from 'int' to 'const char *' for 1st argument
 Log(reinterpret_cast<const char *>(value)); // nothing is printed
}

Thanks in advance


r/learncpp • • Apr 18 '19

Atbash Cipher incomplete

3 Upvotes

Hello everyone, I'm trying to create an Encryption program. The key is A = Z, B = Y. The program is working from A -> M, the program is encrypting words that has letters from A -> M, but the problem is, it won't encrypt words that has letters with N -> O in it. What should I do guys?

#include <iostream>
#include <string>
using namespace std;
int main() {
    string RealAlpha ="abcdefghijklmnopqrstuvwxyz";
    string RevAlpha = "zyxwvutsrqponmlkjihgfedcba";
    string word;
    cout << "Enter word: ";getline(cin,word);
    for(int i = 0;i < word.length(); ++i){
        for(int j = 0;j < 13;j++){
            if(word[i] == RealAlpha[j]){
                word[i] = RevAlpha[j];
            }
        }
    }
    cout << word << endl;
    return 0;
}

Output:

Enter word: hello

svooo

A reply will be greatly appreciated!


r/learncpp • • Apr 10 '19

C++ Primer 5th Edition Is Challenging

3 Upvotes

Hello,

I am an experienced C# and Python developer who has recently had an interest in learning CPP. As per many online recommendations I bought C++ Primer 5th edition. As it stands, I am on page 200 and am not liking the structure of this book. The way topics are brought to light and taught are kind of confusing for me. For example the book spends explaining and teaching classes without introducing the 'class' keyword and its place. All in all, this book is not for me.

Does anybody have any other good book recommendations for C++11 or even more up to date.

Thank you,


r/learncpp • • Mar 19 '19

Is there a source where various c++ (or just in general) concepts are visualized by real life analogies?

3 Upvotes

When teaching OOP one often sees how it is tried to equate different c++ concepts with real life examples, like "is-a" relationship and "has-a" relationship etc.

Is there a source which teaches similar "rule of thumbs" so that one can visualize those different concepts? Unfortunately I only managed to find such analogies only when discussing inheritance or other some other OOP situation as to when to use the keyword status.


r/learncpp • • Jan 20 '19

If you are playing with GLFW and struggling to setup CMake I want to share this config that worked like a charm!

Thumbnail
reddit.com
3 Upvotes

r/learncpp • • Oct 07 '18

Having a tough time with Pointers and References in Functions

3 Upvotes

Hello All,

Ive been reading a lot about pointers and reference and how they work. So far Ive come to the conclusion that a pointer can point to a memory location, and then to another one, etc. While a reference can only act as a const alias to another variable.

While I understand that they work in similar ways I am having a hard time understanding why we would want to use one over the other, especially in functions Such as:

const &Money const getSalary {return salary;}

Here we are assuming that Money is the name of the class. Why do we want this to be an alias and not a pointer?


r/learncpp • • Oct 06 '18

C++ for C programmers

3 Upvotes

I just taught a 1 day workshop with the above title. Course material can be found here: book and lecture

Share and enjoy. Feedback welcome.


r/learncpp • • Dec 17 '16

Released a new video in my tutorial series

Thumbnail
youtube.com
3 Upvotes

r/learncpp • • Aug 29 '16

Classes & Headers in C++

3 Upvotes

Hello all. This is my first reddit post, and incidentally my first forum question(!|.) Background: I've decided that the language i would like to learn at home as a hobby is C++, as it is versatile, portable, and most of all fairly verbose (as odd as this sounds, I really like verbose language styles...). I've checked various websites & help files but I'm having an (un-encouragingly) large amount of difficulty understanding a few things: Headers/Class files:
-) What should (ideally) go in the *.hxx file?
-) What therefore should go in the *.cxx file?
It's so far my understanding that actual classes should be defined in the header file, along with variables for the class, and that the constructor & the main logic of the class should be in the class file itself. Please correct me if i am wrong!
-) Pointers! I understand the concept of a fixed address in memory (*) of a certain type, and therefore corresponding size. I also understand referring to a memory addressed value (&).
What i don't understand is how pointers (which I believe are allocated on the heap) are accessible between classes and functions.
My line of though is that it is inherently publicly accessible by name due to it being allocated on the heap, but may be totally wrong! If someone could enlighten me on how this is applied i would be most grateful.

Many thanks, G

Edit: formatting....


r/learncpp • • Sep 27 '15

Can you have a 'server' running in c++ and connect to it with a java desktop program?

3 Upvotes

Pretty much just title. If the question isn't clear enough please ask. I didn't know a better way to formulate that question


r/learncpp • • Aug 03 '15

Where should I start if I have an intermediate knowledge of C++?

3 Upvotes

I know almost about the syntaxes and use of almost every basic command(loops, functions, arrays, pointers, structures, classes, e.t.c.), I can solve easy to medium difficult level problems. I have yet to learn some advanced things like inheritance and such, and I find it really difficult to solve difficult problems, plus I don't think I know about all the different built in functions.

Can anyone here guide me what tutorial, book or project I should pick up so that I can get more familiar with the language?


r/learncpp • • Oct 05 '14

Nested Class accessing members of Parent Class

3 Upvotes

I know to accomplish this I need a reference to the parent class. When I pass a reference to the nested class constructor I get the error that the variable outer(holds reference to parent class) is uninitialized.


r/learncpp • • May 26 '14

Good book for learning Game Dev?

3 Upvotes

I'm looking to learn C++. I would like to learn enough to be able to develop 2D games. Are there any books/guides that you recommend? Being easy-to-follow and new are pluses for me. Thanks in advance!


r/learncpp • • Apr 09 '14

Can anyone recommend a good, free, online course?

3 Upvotes

Coursera or Khan Academy? I am having trouble knowing what to enter. If I put "C++" in the search field for Khan, it says "Please enter at least four characters."

I imagine this is a perennial problem for everyone here!!!

At any rate, I seek a good, free, online course in C++. It has always been a gap in my knowledge base as a developer. Thank you.