-
August 25th, 2013, 03:50 PM
#26
Re: is possible create a any type variable(1 variable that accept any type of values)
Originally Posted by 2kaud
Now that you have a c++11 compiler, you might want to revisit where all this started - How can I convert write procedure to cout
http://forums.codeguru.com/showthrea...cedure-to-cout
and see my post #15 with the solution using variadic templates. As gcc 4.8.1 supports variadic templates, this code should compile and give you the write function you originally wanted without using the variant class - which I suspect is going to give more trouble than it's worth .
Code:
#include <iostream>
using namespace std;
void write()
{
cout << " ";
}
template <typename A, typename ...B>
void write(A argHead, B... argTail)
{
cout << argHead << " ";
write(argTail...);
}
int main(void)
{
write(1, 2, "qwerty", 4.45, "five", 6);
return 0;
}
thanks.
now i'm doing the same for read(): but i get errors:
Code:
void read()
{
cin >> " ";
}
template <typename A, typename ...B>
void read(A argHead, B... argTail)
{
cin >> argHead >> "";
read(argTail...);
}
don't forget theres these type of read too:
Code:
void read()
{
DWORD oldMode;
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldMode);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT);
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
char buffer[1];
DWORD read;
ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &read, NULL);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), oldMode);
CloseHandle(GetStdHandle(STD_INPUT_HANDLE));
}
thanks you for all my friend.. thank you both
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|