-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathva.cpp
More file actions
53 lines (48 loc) · 883 Bytes
/
va.cpp
File metadata and controls
53 lines (48 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <bitset>
using namespace std;
#include <functional>
using callBack = function<void(int)>;
//±ß½ç
void print()
{}
template <class T,class ...Arg>
void print(const T & fitstArg, const Arg& ...arg)
{
cout << fitstArg <<sizeof...(arg)<< endl;
print(arg...);
}
void printMsg(const char * format)
{
while (*format)
{
if (*format == '%'&&*(++format) != '%')
{
throw std::runtime_error("invalid format");
}
cout << *format++;
}
}
template <class ...Arg,class T>
void printMsg(const char * format,T value, Arg ...arg)
{
while (*format)
{
if (*format == '%'&&*(++format) != '%')
{
cout << value;
printMsg(++format, arg...);
return;
}
cout << *format++;
}
throw std::logic_error("error arg");
}
int main()
{
int x = 3;
printMsg("%d \n\n", x);
// print("aaaaa", std::bitset<8>(123), 123, 324);
getchar();
return 0;
}