What does boost::locale::generator need? - c++

I'm pretty new to boost and want to use it's boost::locale to make suitable conversations to lower case. But I've got a link problem with boost::locale::generator. I linked my project with libboost_locale-mt.a and switched header search paths correctly, but it isn't enough for some reason. I'm using Xcode, and I got linking mistake on this code:
#include <boost/locale.hpp>
int main(int argc, const char * argv[])
{
using namespace boost::locale;
using namespace std;
generator gen;
std::locale loc = gen("");
locale::global(loc);
cout.imbue(loc);
cout << "This is lower case " << to_lower("Hello World!") << endl;
return 0;
}

Related

Crypto++ : Hash generation hangs on windows 10

I have the following simple program :
#include <cryptlib.h>
#include "sha.h"
#include <sha3.h>
#include <filters.h>
#include <hex.h>
#include <beast/core/detail/base64.hpp>
using namespace CryptoPP;
using namespace boost::beast::detail::base64;
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "missing argument 1 : password";
return 0;
}
std::string password = std::string(argv[1]);
byte digest[SHA3_256::DIGESTSIZE];
SHA3 digestAlgo = SHA3_256();
std::cout << "going to calculate the digest\n";
digestAlgo.Update((const byte*) password.data(), password.size());
std::cout << "updated...\n";
digestAlgo.Final(digest);
std::cout << "calculated the digest\n";
char* b64encodedHash = (char*)malloc(sizeof(byte)*1000);
encode(b64encodedHash, digest, sizeof(byte)*1000);
std::cout << "password hashed : " << b64encodedHash << "\n";
return 1;
}
When I run it the text : "going to calculate the digest" is output on the command line and the program does not continue. It hangs.
Does anyone know why ? I am trying to follow the examples on the Crypto++ wiki, and this is very similar to theirs.
After the Final call I want to base64 encode the digest, you can remove that part, it uses a boost header file.
Thanks,
Regards
Change the line
SHA3 digestAlgo = SHA3_256();
to
SHA3_256 digestAlgo;

How to Link External libraries in c++(windows 10) using command line?

after google search, I came up with this Solution
g++ finlename.cpp -I{include file directory address} -L{Library file directory address}
-l(linkeroptions)
seems like this doesn't work for me. when I compile using this I get an error stating:- cannot find the headername.h(header file that was included in my program of the external lib).
file:-
#include <iostream>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv)
{
cout << "Hello world!" << endl;
return 0;
}

when i use the c++ string in my code it compiles but i don't show an output

I don't know whether I have installed cygwin wrong or what but the code compiles fine but it doesn't show the output. Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string name;
cout << "Enter the name of the person" << endl;
getline(cin, name);
cout << "Name is: " << name << endl;
return 0;
}
Here's the compilation image and the execution:
Your code is fine. The correct way to call the executable using Cygwin is ./string.exe
As I can see, you use cygwin. I had the same issue with gcc 5.2. Try to install gcc 4.9 and all corresponding libraries for this version instead.

Bug converting std::tr2::sys::path to std::string?

I am using the Visual Studio 2013 TR2 filesystem library. I am seeing a bug when converting a UNC path to a string:
#include "StdAfx.h"
#include <filesystem>
#include <iostream>
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
namespace fs = std::tr2::sys;
fs::path fsPath = "//server/dir";
std::string sPath = fsPath;
std::cout << sPath.c_str() << "\n";
}
This will output "\server\dir", not "\\server\dir".
Is there a fix or a workaround for this? Am I doing something wrong?
Well I found a workaround that works for me. If I use
sPath = fsPath.string();
I can now pass that string to the std::ifstream constructor. The path string will be "//server/dir" rather than "\\server\dir".

How to use wstring and wcout to output Chinese words in Xcode?

I try to run the code blow in Xcode 4.2:
int main(int argc, const char * argv[])
{
locale loc("chs");
locale::global(loc);
wstring text(L"你好");
wcout << text << endl;
return 0;
}
I got a error "Thread 1:signal SIGABRT".
Can you Tell me why the error happen or how to use wstring and wcout to output the Chinese words?
You don't. Mac, like other Unix systems, uses UTF8 while Windows uses "Unicode" (UTF-16).
You can print that perfectly well on Mac by using string and cout instead of wstring and wcout.
ADDENDUM
This sample works great. Compile with g++ and run as-is.
#include <string>
#include <iostream>
using namespace std;
int main(int arg, char **argv)
{
string text("汉语");
cout << text << endl;
return 0;
}
The crash is coming from the call to locale(). This SO answer seems related.
As mentioned by Mahmoud Al-Qudsi, you don't need it as you can use UTF-8 in a normal string object:
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
string text("你好");
cout<<text<<endl;
return 0;
}
Produces:
$ ./test
你好
EDIT: Oops, too late :)