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.
Related
This question already has answers here:
Quick sort at compilation time using C++11 variadic templates
(2 answers)
Closed 7 years ago.
I wonder it it is possible to sort numbers during compilation? I mean something like that:
template<int...>
void sort(){
...
}
And:
sort<2,4,5,13,453>();
And I don't ask of solution or something like that. Please give me a hint or reference me.
Since C++ template system is known to be turing-complete, you can in principle compute everything that is computable at compile time. That includes sorting algorithms.
This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.
There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.
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.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Calling functions from main() in c++
Hello.
I have a programme that has about 100 classes and more than 1000 functions spread over 20 header and source code files. What I want to know is that how I can pass arguments to so many functions in so many files? What is the procedure adopted for this in main()?
Regards,
Supriyo
Take a look at the Boost.Program_options module.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C++ struct sorting
Is it possible to sort a vector in C++ according to a specified sorting method, like used in Java's Collections.sort that takes a Comparator?
Yes. See the answers to this question from this morning: C++ struct sorting
Yes, it is. Take a look here for an example.