Error: Function stoi Not Declared (-std=c++11 is Enabled) - string

I'm using Code::Blocks 16.01 on Windows 10.
I need to convert a string to an integer.
So I'm trying to use stoi, but it says it's not declared.
I have enabled -std=c++11 in compiler settings but it still gives me an error:
'stoi' was not declared in this scope
Screenshot of Code::Blocks:
The part of the code which causes the error is:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
int n,m,k;
string nmk;
ifstream test("input00.txt");
if (test.is_open())
{
getline (test,nmk,' ');
n = stoi (nmk,NULL,10);
getline (test,nmk,' ');
m = stoi (nmk,NULL,10);
getline (test,nmk, '\n');
k = stoi (nmk,NULL,10);
}
}

Related

How to fix QDialog transparent background afterimage issue in qt embedded (QT4.7.3)?

I am using embedded system and I'm testing transparent QWS server where is my Qt4.7.3.
I faced the afterimage in the QDialog when moving cursor in test program which as the QWS client, but it didn't happen in the QMainWindow which in QWS server program.
Can anyone help me to fix the issue?
There is the issue
Here is test program source code.
#include "mainwindow.h"
#include <QApplication>
#include<QWSServer>
#include <QDialog>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "qscreenlinuxfb_qws.h"
#include "qscreendriverfactory_qws.h"
#include <errno.h>
extern "C" {
extern int Test();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog w;
QWSServer::setBackground(QColor(0,0,0,0));
QWSServer::setCursorVisible(false);
w.setStyleSheet("background-color:transparent;");
w.show();
return a.exec();
}
OK I found the issue. In QT source code.
src\gui\embedded\qscreen_qws.cpp
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
}
to
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
QPixmap temp = QPixmap(blendSize);
temp.fill(Qt::transparent);
**blendbuffer = temp.toImage();
}

#include errors detected in vscode in Centos

I try to run code in vscode but I got #include error...
#include <iostream>
using namespace std;
int main()
{
cout << "Hola!!"
}

error: ‘scmp_filter_ctx’ was not declared in this scope

I am getting compilation error:error: ‘scmp_filter_ctx’ was not declared in this scope.
I have declared a seccomp filter.
scmp_filter_ctx ctx;
I have included the library #include <linux/seccomp.h>
and already installed the library libseccomp-dev using
sudo apt-get install libseccomp-dev.
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <bits/stdc++.h>
void create_sandbox(){
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_KILL); // default action: kill
seccomp_load(ctx);
}
I managed to solve this error using the following:
Replaced #include <linux/seccomp.h> with #include <seccomp.h>
and while compiling, used g++ filename.cpp -lseccomp.
This worked for me.

Error: Struct already definded in *.Obj

Help, I'm using VC++ and I always get the LNK2005 and LNK1169 Error when running my script, can you guys please tell me why it's happening and how to fix it, Thank you!
Code:
In the Main.cpp
#include "stdafx.h
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "Modifier.h"
using namespace std;
HWND myconsole = GetConsoleWindow();
HDC mydc = GetDC(myconsole);
int main()
{
if (Input.beg("Hello"))
{
cout << "World";
}
cin.ignore();
}
In "Modifier.cpp"
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct {
bool beg(string a)
{
string b;
getline(cin, b);
if (b == a)
{
return true;
}
else
{
}
}
} Input;
In "Modifier.h"
#include "Modifier.cpp"
You must change your header declaration: you're inadvertently declaring a different, global "Input" variable in every .cpp that includes "Modifier.h".
SUGGESTION:
// Modifier.h
#ifndef MODIFER_H
#define MODIFIER_H
struct Input {
bool beg(string a)
{
string b;
getline(cin, b);
if (b == a)
{
return true;
}
else
{
}
}
};
#endif
Then, in Modifier.cpp:
#include "Modifier.h"
struct Input globalInput;
You should not include a .cpp in a .h. You should include headers in source files, not vice versa.
And you should definitely consider using a "class" instead of a "struct". Because, frankly, that's what your "Input" is: just a method, no state/no data.

getting CLOCK_TICK_RATE value in linux

I'm trying to print the value of CLOCK_TICK_RATE with the following program:
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/kd.h>
#include <linux/timex.h>
int main() {
printf("%d\n",CLOCK_TICK_RATE);
}
I get an compilation error:
error: ‘CLOCK_TICK_RATE’ undeclared.
I looked for the definition of CLOCK_TICK_RATE, I found that in timex.h, but even after I included timex.h CLOCK_TICK_RATE is still undeclared.
thanks in advance.
Maybe you are looking for this?
#include <stdio.h>
#include <unistd.h>
int main (void) {
printf (
"%ld\n",
sysconf(_SC_CLK_TCK)
);
return 0;
}
It's in hertz and is normally 100.

Resources