Is there a way to get regional time format with Boost? - c++

as I tried to ask in my title, I am talking about regional time format. I have an application that can display the time/date, but from US users I get the question of why am I displaying the time like this: 21:30 instead of this: 9:30PM. Same thing for the date to which I display the date as 22.05.2018 instead of 05.22.2018.
So my questions is: Is there a way to achieve getting a timezone flag or location or even the time already formatted so that I can display the time/date different for different regions?

With Boost Locale
double now=time(0);
cout << as::datetime << as::local_time << "Local time is: "<< now << endl;
cout << as::gmt << "GMT Time is: "<< now <<endl;
cout << as::time_zone("EST") << "Eastern Standard Time is: "<< now <<endl;
Parse date from string back and add the time-zone

Related

How to format output of a SQL query in C++?

Im working on a school assignment in which i need to format a query of some dummy data. The specific query gathers data on a few fields in a set of two tables, and prints it out to the console in C++.
While this works as expected, the only issue is formatting output so that it appears correctly. In our example output in the assignment document, this is shown as being the proper output
<ID> <name> <email> <phone> <ext> <manager>
not the exact spacing but more or less what needs to be done. The initial output i get in the console is similar to this, and looks like:
1056 Tim Tomphson ttomph#fakeEmailService.com +1 800 555 1580 x5122 Tom Timsphon
Until about a few entries down when suddenly the data becomes completely unformatted.
Now im confused, cause I thought i had the formatting right, and dont know why its fallen to hell around that point specifically since everything else up to that was basically perfect. and i dont know how to format it right so that it can return to a proper tabular output.
the code im using for this output is
cout << left << setw(10) << temp.empNum << "\t" << temp.firstName << " " << temp.lastName << "\t\t" << temp.email << "\t\t" << temp.phone << "\t\t" << temp.extension << "\t\t" << temp.reportsTo << endl;
I've also tried using printf statements, but that had less luck and was nowhere as close to successful as this command itself...does anyone have any ideas that could help me out?

How to detect keypress combination in OpenCV C++

I am having trouble detecting a combination of keys being pressed at the same time in an OpenCV program written in C++. I would like to be able to detect for example 'w' & 'a' at the same time.
I have tried cvWaitKey and cvWaitKeyEx, but both seem to return regular characters and either one key or another for keys pressed at the same time:
//![check_keypress]
char c = (char)waitKeyEx(1);
std::cout << "c: " << c << " " << (int) c << "\n";
Is there a way to do this or can another library be utilized to do so? I have checked other posts such and I have not been able to find a solution.
Thanks

Making a text box in c++

I'm programming some very simple stuff and I want to make a neat little "text box" at the beginning of my program in the command prompt with some basic info. An example of what I mean:
cout << "Creators: J. Adams & T. Jefferson" << endl;
cout << "Nicknames: Johnnny & Tommy" << endl;
cout << "Age: 20 & 21" << endl;
cout << "This program is for ..... << endl;
This is just an example, and one of the things I'd like is a simple way to align these things (so that "Johnny" is directly below "J. Adams", or at least directly enough so you know they belong together). I know of setw but you have to include for that, and I'd like a method where you don't have to use that.
Other than that, I'd like a simple way to put an outline around the text (that's what I mean by text "box"). Nothing to fancy, just something you can do with the first 128 normal characters. I've googled around for something similar to no avail.

Mongodb Update using C++ API

I have written a C++ function to update a mongodb document. It is as below.
void
LocationDb::setServingRouter(string sensor, string oAp, string nAp) {
m_conn.update("location_db.ldb",
BSON("id" << sensor << "name" << "/temp/s/1" << "ap" << BSON("name" << oAp)),
BSON("id" << sensor << "name" << "/temp/s/1" << "ap" << BSON("name" << nAp)));
}
This update query is working; however, I believe it has some limitation i.e. every time I update, I need to pass it the old ap name (oAp).
I find this very annoying in the sense that I just want to update the ap name without bothering was old name is. As per this query implementation, it is first finds the matching record in the document, and then update it.
How can I just update by matching the query partially? Bottom line is that I don't want to remember what old record was. Any help?

cgicc - cgi.getElements(), which method? get or post?

cgicc can process form elements quite well , but how can i know whether the data is generated from get_method or post_method?
the piece of code i used:
cout << "Content-type:text/html\r\n\r\n";
try {
Cgicc cgi;
const_form_iterator iter;
for(iter = cgi.getElements().begin();
iter != cgi.getElements().end();
++iter){
cout <<
"<table><tr>" <<
"<td>" << iter->getName() << "</td>" <<
"<td>" << iter->getValue() << "</td>" <<
"</tr></table>" << endl;
}
}catch(exception& e) {
cout << e.what() << endl;
}
update:
i find this from the cgicc official page: "Parses both GET and POST form data transparently." (http://www.gnu.org/software/cgicc/)
it seems that cgicc don't want to separate get and post by design?
You can find the HTTP method (ì.e. GET, POST, etc...) of a request using cgicc::CgiEnvironment::getRequestMethod
I think the only way to solve it is by checking whether there is a variable name in the GET method query string that's the same name of the one in the POST method. This means that the variable name must be mentioned ONLY ONCE either of the two methods. In other words, if you combine the variables of the GET method with the variables of the POST in a single set, the variable name must be mentioned once in this set.