forked from rizonesoft/Notepad3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample4.cpp
More file actions
34 lines (28 loc) · 1.08 KB
/
example4.cpp
File metadata and controls
34 lines (28 loc) · 1.08 KB
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
#include "tinyexpr.h"
#include <cstdio>
#include <locale>
#include <clocale>
int main(int argc, char *argv[])
{
/* Set locale to German.
This string is platform dependent. The following works on Windows,
consult your platform's documentation for more details.*/
setlocale(LC_ALL, "de-DE");
std::locale::global(std::locale("de-DE"));
/* After setting your locale to German, functions like strtod() will fail
with values like "3.14" because it expects "3,14" instead.
To fix this, we will tell the parser to use "," as the decimal separator
and ";" as list argument separator.*/
const char *expression = "pow(2,2; 2)"; // instead of "pow(2.2, 2)"
printf("Evaluating:\n\t%s\n", expression);
te_parser tep;
tep.set_decimal_separator(',');
tep.set_list_separator(';');
if (tep.compile(expression)) {
const double r = tep.evaluate(); printf("Result:\n\t%f\n", r);
} else {
/* Show the user where the error is at. */
printf("\t%*s^\nError near here", tep.get_last_error_position(), "");
}
return 0;
}