This question already has answers here:
C++ standard output format
(2 answers)
Closed 10 years ago.
I'm still new to C++ so bear with me.
I'm currently making console output applications and I want to make a simple matrix calculator. So I want the user to input 4 values for each element of the matrix. Each element should be at a different xy position on the screen. So it makes up a square, a simple 2x2 matrix.
I don't have a clue how to change the position of text in C++ though. I used the Pascal programming languages before and all you had to do was 'gotoXY(20,40)' followed by a statement.
I know this is probably an easy question, I can't seem to work it out though.
If this is on Windows, you should use SetConsoleCursorPosition. I think I have the right helper class for you here: Helper Class for Console Functions.
Related
This question already has answers here:
'colon' and 'auto' in for loop c++? need some help understanding the syntax
(3 answers)
Closed 7 months ago.
this is a quick question, Im translating a program that's in C++ to C, and I saw this line of code,
for (int v : adj[u]) {
referenced in this article: link
and I am not really sure what it does. I tried googling it and got results for range based for loops in C++, but cannot find anything that has this exact syntax and what it means. Help would be much appreciated.
It's a very simple for loop that iterates over the elements of adj[u], going 1 by 1.
This question already has answers here:
How can I set the decimal separator to be a comma?
(2 answers)
Closed 2 years ago.
So I am at the start of my programming career and I wrote a code for a simple vending machine on C++.
The problem is, when people pay, they need to input their change into the console like: " 0.50€" for 50 cents. The problem is I live in Europe, and most of the people put in commas as floating numbers like "0,50€". The program collapses when this happens. How do I solve this elegantly? With either the program discovering it and mentions their failure so they can type it in correctly or, better, accepts it as a normal floating-point number.
It is a matter of locale settings.
This question may help you in setting the locale you need in your program.
This question already has answers here:
ID field intermittently lost in custom point class
(2 answers)
Closed 4 years ago.
I'd like to use 2D points with attributes for the polygons.
The attributes should be assigned to any new points according to some kind of strategy.
Do you know if it is possible and how to do it?
Is there any doc describing how to do it?
Last time I looked at things it proved impossible. That's because the library does construct new points using the available (accessor) traits.
Similar/related questions:
ID field intermittently lost in custom point class
In fact, let me dupe-vote that!
This question already has answers here:
Getting terminal width in C?
(8 answers)
Closed 7 years ago.
I have a few general questions about writing C++ programs and running them from Unix shells. Is there a way to ask the shell for it's size? Either in pixels, characters, whatever? What about relocating the cursor within the window? How would you do this if you needed to?
With the ncurses library, getting the terminal width (in characters) is as easy as calling the function getmaxx. Similarly, getmaxy returns the height, and getmaxyx gets them both at once.
The cursor can be moved by calling move with the x and y coordinates.
Check NCURSES it is what I think you are looking for.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Dump facility in C++ like var_dump() in PHP?
I'm not sure does C++ even allow this kind of thing, but I was wondering, could it be possible to write a generic function that could output any type array (std::vector) as plain text, as long as I write myself each of the types output function, for example std::string, float, int, etc.
So, how could I go through the structs types and output them one by one by different output functions made by me?
You should have a look at cxx-prettyprint. http://louisdx.github.com/cxx-prettyprint/
I think it does all your asking for.