Copy a string to clipboard in Linux KDE Plasma - c++

I am doing a GUI program in C++ and I use OpenSuse with KDE Plasma. I would like to copy to clipboard a string. How can I accomplish that?
Here is my code:
#include <wx_pch.h>
#include <wx.msgdlg.h>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
void SimpleGUIFrame::CopyToClipboard(string str)
{
// copy str to cliboard
}

Related

VSC “Format Document” messes up #include order

My problem is pretty much what the title says:
When I use STRG-ALT-F to format my C++ files VSC also messes with the order of #includes.
And of cause this leads to errors that were not there before… :-(
For example this
#include "soc/soc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "XClk.h"
#include "DMABuffer.h"
becomes this
#include "DMABuffer.h"
#include "XClk.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "soc/soc.h"
… and subsequently fails compile.
Is there a way to forbid the formatter reordering and stick to formatting stuff?
Using PlatformIO in VSC on OSX.

Where to get _fileno and _O_U16TEXT?

I'm trying to print the text "Ääkkösiä ruutuun." to console with c++. I have windows 7 and am using Code::Blocks editor. Searching on the subject I found that maybe these sort of lines would help
_setmode(_fileno(stdout), _O_U16TEXT);
wstring s{L"Ääkkösiä ruutuun."};
wcout<<s<<endl;
But when I try to compile it, I get the error: _fileno was not declared in this scope.
I have all these includes:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdexcept>
#include <cmath>
#include <sstream>
#include <fstream>
#include <codecvt>
#include <locale>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <cstdio>
#include <ostream>
what am I missing?
Also, one other thing I tried was locale, but then locale::empty wasn't found! Why doesn't my c++ have anything in it?
EDIT
Here is a picture of what my program is doing now.
It prints out just the first letter (Ä). What happens to the rest?
Ok, it seems that setmode sets it so that only one letter gets printed. (Even trying to print normal texts with multiple commands, just results in a single letter.) Without it the scandinavian letters don't print correctly, thought. They look like this:
The answer you found is for Visual Studio, not Code::Blocks.
While the C standard specifies what should in in <stdio.h>, it only specifies a minimum. Implementors may add their own functions, and should do so using an _ (underscore prefix). This is why you should NOT use that prefix. You don't know what you'll break. Microsoft clearly signaled their non-standard extensions using the correct prefix.
The answer is tagged C++, but C++ inherits the contents of <stdio.h> from C.
The line
setlocale(LC_CTYPE, ".OCP");
works!
A complete example:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
wstring readFile(const char* filename) {
wifstream wif(filename);
locale myLoc("");
//locale utf8_locale(locale(), new gel::stdx::utf8cvt<true>);
wif.imbue(myLoc);
basic_stringstream<wchar_t> wss;
wss << wif.rdbuf();
return wss.str();
}
int main() {
setlocale(LC_CTYPE, ".OCP");
wstring contents = readFile("test.txt");
wcout<<L"Does anything get printed out at all???"<<endl;
//wcout <<contents<<endl;
wstring s{L"Ääkkösiä ruutuun."};
wcout<<s<<endl;
wcout<<L"Näkyykö äkköset?"<<endl;
return 0;
}
The text read from file (utf-8) still doesn't print correctly, though.
It should be
Hei!
Täällä on kaksi riviä.
ä's go awry there.
Output:

std::getline get error in JNI

I am using jni and want to read file from path, i used:
while (std::getline(file, str)) {
...
}
but it get an error : Function 'getline' could not be resolved, i have added:
#include <vector>
#include <string.h>
#include <jni.h>
#include <fstream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <iostream>
and they are Ok. How do i resolved this problem? Please help me.
use:
#include <string>
instead of:
#include <string.h>
The latter one is the C variant and will not have the std namespace. Also see:
Difference between <string> and <string.h>?

SIGSEGV while debugging in CodeBlocks

I am running 32 Bit CodeBLocks(10.05) in my 64 Bit machine. It produces SIGSEGV all time. This is occurring in my Office PC. But in my home PC (32 bit and 10.05 codeblocks) no problem occur. I am attaching Call Stack window. Is there any problem with kernel32.dll ?
Please note that, for testing I just wrote a line of code. But still it produces SIGSEGV. I re-installed CodeBlocks 2-3 times. Is there any problem in my System ? I am almost crazy. :'(
As requested I am putting the simple code here:
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
//READ("input.txt");
//WRITE("output.txt");
int i, j, k;
int TC, tc;
int x0, y0, x1, y1;
cout << "hi";
return 0;
}

Weird VC++ Intellisense Behavior

Intellisense is broken with this code, everything is undefined to Intellisense from tree header:
#include "tree.h"
#include <iostream>
#include <ctime>
#include <string>
#include <list>
But when I move my own bst implementation header file down a bit, Intellisense starts working again.
#include <iostream>
#include <ctime>
#include <string>
#include <list>
#include "tree.h"
Why is this?