My buffer dont "work". #3847
Replies: 2 comments 2 replies
-
I've also used IM_ARRAYSIZE(buf) instead of sizeof(buf), but still the same xD |
Beta Was this translation helpful? Give feedback.
-
You can't compare You either need to use if (strcmp(buf, "rando") == 0) { or concert one of the buffers to if (std::string(buf) == "rando") {
You're using
As you might've guessed by now, this wasn't the source of your problem so you could change it back. For As an aside, make sure you pay attention to your compiler warnings. Warnings almost always mean "What you're doing is technically valid C++ but it looks wrong." (At this point in your learning, you should generally assume the compiler is right and you're wrong.) Both MSVC and Clang emit warnings for your code:
(GCC doesn't seem to warn for this unfortunately.)
No worries, we all gotta learn at some point! Strings in C/C++ have a bit of a learning curve compared to other languages. Next time consider inspecting the contents of To do that, you could either print it to the console: // C-centric way that still works in C++:
printf("%s\n", buf); // Include <stdio.h>
// C++-centric way:
std::cout << buf << std::endl; // Include <iostream>
// Both techniques have the same result, it really boils down to which one you prefer.
// If you're working in a code base with other people, use whatever is being used elsewhere. or you can also inspect the values in your debugger. How you do this depends on your development environment. With most IDEs, click the margin to the left of your code (and left of the line numbers) and a red circle will appear. This red circle represents a breakpoint. When you run your app, it will be paused when it his the breakpoint, allowing you to inspect the contents of variables and such. If you place a breakpoint on your The box underlined with red is what appears when I hovered my mouse over Some other useful tools visible here as well, such as the Call Stack view at the right-bottom and the Step Into, Step Over, Step Out buttons in the toolbar towards the right-top to the right of the Stop button. For example, you could hit the Step Over button to see how your program flows through the code. (In this case, you'd see it'd always skip over the The Call Stack view basically shows you how your program got to this point and what function it will resume when the current one returns. In this screenshot you can see the current function is Debuggers are very powerful tools and are worth learning, but there's also no shame in |
Beta Was this translation helpful? Give feedback.
-
Hello. I'm trying to make a simple login system using ImGui.
I've made 2 TextInputs, one aks for the usernam, the other one asks the password. But when i try to check their value, they don't seem to have any value stored inside. Look at the code:
(Also, i still learning C++. I'm sorry if this is a dumb question).
And when i type the username in the text field one (buf) and press the button, even if it has the value "rando" (the correct username), it don't login with "authed = true".
(authed is the variable that initialize the program menu once the login is successful.
Can someone help me?
Beta Was this translation helpful? Give feedback.
All reactions