Questions tagged [c++11]
Use this tag for code that must compile as C++11 (not using any features introduced in C++14 or later).
53,571
questions
1
vote
2answers
40 views
warning: 'auto' type specifier is a C++11 extension
I have a very simple C++ code statement auto a = 12;.
When I am compiling it with g++ in Linux using -std=c++98 option I am getting an error as expected
error: ‘a’ does not name a type
But when I am ...
-4
votes
0answers
11 views
Please give the solution in C++ program [closed]
Write a program in which increment in pointer to integer should demonstrate increment in integer using reinterpret_cast operator.
0
votes
0answers
28 views
C++ Getting Garbage Values while taking input [duplicate]
I am getting garbage values while taking input in C++.
I'm taking Input and storing it in matrix using vector.
If there are other way you can suggest me that too, but how can I solve this?
#include &...
0
votes
0answers
35 views
excercises on object oriented programming [closed]
Can someone suggest a book or website with excersises on object oriented programming.(AVL trees ,graphs,classes,binary trees ,graphs with vectors) for practice? Thow we have studied theory we can't ...
0
votes
0answers
10 views
I cannot complile when using eig_sym from Armadillo
When i try to compile my code which uses eig_sym from Armadillo it gives this error
Undefined symbols for architecture x86_64:
"_wrapper2_dsyev_", referenced from:
void arma::lapack::...
3
votes
2answers
79 views
Use std::set with input order preserved
I would love to use std::set to store integers that have to be unique, but I don't want them to be sorted (e.g. I need the order of input to the set preserved)
For example:
set<int> exampleSet;
...
1
vote
1answer
48 views
Understand the constructor and the assignement c++
I’m a newbie in C++ and I come from C. The OOP is a whole new paradigm for me.
So I will ask a question on this stupid example:
#include <iostream>
class Object
{
public:
int first;
int ...
0
votes
0answers
60 views
Returns as value or as reference through parameter?
std::vector<std::string> get() {
std::vector<string> result {};
for (int i = 0; i < 10000) {
result.emplace_back("test" + to_string(i));
}
return ...
0
votes
0answers
16 views
How to solve Exception in thread “main” java.util.zip.ZipException: error in opening zip file
I am using qt and get this error message when build for android. I dont understand why give this. Please help me. Thanks.
:-1: warning: Android: The main ABI of the deployment device (arm64-v8a) is ...
0
votes
1answer
49 views
When a map is copied to another existing map, what happend in details?
int main ()
{
std::map<char,int> foo,bar;
foo['x']=100;
foo['y']=200;
foo['z']=300;
bar['x']=100;
bar['y']=2000;
bar['zz']=400;
foo=bar;
return 0;
}
Is it such a process ...
0
votes
2answers
37 views
C++ not outputting to output file
Hi I'm trying to setup and run my first c++ file in sublime and I'm running into the issue where my values aren't outputting. I'm using the below guide:
https://medium.datadriveninvestor.com/how-to-...
0
votes
0answers
40 views
Fix for universal reference cannot bind to packed struct fields in gcc/g++ and side effects
This isn't the same as other answers for similar question. They need
source code modification in the caller . This fixes the problem in
callee without modifying caller's code. Passing reference of ...
-1
votes
0answers
16 views
Installed sublime text 3 for c++ but showing “No such file or directory” include “wchar.h”
I've been trying to run simple c++ program
#include<iostream>
using namespace std;
int main(){
cout<<"helloworld";
}
But got a error like this:
In file included from ...
1
vote
4answers
84 views
C++ template functions accepting parameters in random order
I am writing a C++ network library and would like the main (template) function to accept parameters in random order, to make it more user friendly, in the same way the CPR library does.
The template ...
0
votes
1answer
59 views
Trying out a problem but code I had written is not giving output for large numbers. why?
I was trying this question.
The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?
And I had written the following code:
#include<iostream>...
0
votes
0answers
31 views
C++ thread pooling with function that adds new tasks recursively and dynamically
Here is a function which recursively generates tasks and a thread pool is used to perform these tasks.
ThreadPool pool{1}; // only one thread in the thread pool
std::function<void(int)> func;
...
0
votes
0answers
43 views
recursive function with std::async stuck from some size of std::vector
I rewrite function who get all combination of vector. I tried to run it asynchronously, when the vector size is 5 - getAllCombinationOfVector({ 1,2,3,4,5}) it work fine. when the vector size is 6 it ...
0
votes
1answer
42 views
Conditional using statement depending on a template parameter being a tuple or not
In a template class with two template parameters T and U, I'd like to define an alias which is the tuple {T,U} if U is not itself a tuple (T is never a tuple) or the tuple {T,U0,...,Un} if U is the ...
0
votes
0answers
26 views
C++ problem with sf::sprite in a std::vector not keeping its updated position (despite passing by reference)?
In main, create soldier object
Soldier soldier;
create soldier sprite and set its position
//Load a soldier sprite
sf::Texture texture2;
if (!texture2.loadFromFile(resourcePath() + "soldier....
-1
votes
0answers
23 views
Why can't I erase a set element without using an iterator? [duplicate]
I am trying to delete odd numbers in a set. I can't seem to do it without having to use an iterator. My compiler throws an error. Please help!
This works:
void remove_odd(set<int> &s) {
/...
3
votes
1answer
71 views
C++: use void as template argument
I have this minimal class to represent an event which client can subscribe to.
The event can have an data type associated to it, so when it is triggered by a publisher, an argument of that type would ...
-5
votes
1answer
31 views
code not working? It is giving me error and i am not able to solve [closed]
This piece of code is giving me this error: expected initializer before 'void'
void num(int a)
plz explain
#include<iostream>
using namespace std;
int main()
void num(int a)
{
if(a%2==0)
...
0
votes
0answers
37 views
g++ including iostream gives a compilation error on a nearly identical system, why?
Weird issue, I have two systems, CentOS Linux release 8.3.2011, and they are nearly identical from a package standpoint, everything that's installed on one is also installed on the other, with minor ...
1
vote
1answer
71 views
Why C++ allows returning ifstream object?
In C++98, the following code does not compile because the ifstream has no copy constructor:
#include <iostream>
#include <fstream>
using namespace std;
ifstream f() {
return ifstream(&...
0
votes
2answers
65 views
Convert sorted floating point numbers into alphabetically sorted strings
I need to convert C++ double precision numbers into strings in such a way that sorting the strings alphabetically will deliver the same order as sorting the numbers arithmetically.
I'm considering ...
0
votes
0answers
26 views
returning by reference and copy the value
i was reading about r-value references in c++ and i saw this example. i tried to understand why the returning value in line 15 isn't a copy while the returning value in line 14 is but i couldn't.
1 ...
0
votes
3answers
81 views
Does the swapping an array of object around affects the pointers that pointing at it
When swapping or moving an array of objects, what happens if lets say there were pointers pointing to random objects in the array. Does the pointer follow the objects element as they move or not? If ...
-1
votes
5answers
99 views
How to compare strings in c++ so as to sort them in a dictionary order? [closed]
I want to create a function to compare two strings in dictionary order so that I can sort the strings "aa", "AA", "Bb","bb" in the order "aa" < &...
-2
votes
0answers
26 views
Can someone explain to me what the & is here for? [duplicate]
This is a function name, and I can't understand what the first argument is. What I can understand is that a matrix is being created. But what's the & here for? and is the matrix named as matrix?
...
0
votes
2answers
70 views
How do I get two different random numbers in the same srand() seed? C++
I am trying to create a random password generator. When I call the function multiple times it returns the same character value. QQpQ;7Q7pQ;p
I have tried adding srand(time(0)); or srand((unsigned int) ...
2
votes
1answer
84 views
Re-initializing random distribution
Is it reasonable to expect that a distribution from <random> re-initialized before each next number request behaves the same way as if it was initialized once? In other words, does this:
std::...
0
votes
2answers
44 views
C++ array declaration on heap?
In C++ we can write:
int arr[] = {20,3,2,0,-10,-7,7,0,1,22};
//Smal Note: Why int *arr = {20,3,2,0,-10,-7,7,0,1,22}; won't work? I learnt I can replace [] with *
but what if I want to allocated ...
1
vote
1answer
45 views
how endl mainly affects fully buffered streams?
https://www.cplusplus.com/doc/tutorial/basic_io/
In the following site, just before cin heading, it is stated that
The endl manipulator produces a newline character, exactly as the insertion of '\n' ...
0
votes
1answer
93 views
Constructor Exception handling
I think there is memory leak as B constructor not called.
What is best way to handle exception in constructor if that constructor allocates objects of other class and if at some point exception occurs ...
2
votes
2answers
50 views
What is the correct behavior of std::get_time() for “short” input
I'm trying to understand what should be the correct behavior of C++11
std::get_time() when the input data is "shorter" than expected by the format
string. For example, what the following ...
0
votes
0answers
22 views
Can't use constexpr function in static_assert
tell me, please, why I can't use my constexpr recursive function to static_assert if string contains needed count of symbols? Constexpr function supposed to be a constant value, but VS2015 compiller ...
0
votes
1answer
49 views
Prompt input until a mimimum number of values is entered
I am writing a small program in which I have to search for smallest and largest element entered.
The thing is I have made an array 10 elements wide and the user should enter at least 5 element.
If the ...
1
vote
0answers
47 views
multiple definition of “<some_function>” error while compiling cuda code with cpp
Hi I am trying to build a custom python package which includes cuda files and corresponding cpp and header files.
My directory structure looks like this
Apology for a bit long question below. I am ...
0
votes
1answer
34 views
C++ : Error while deducing types for templated function [duplicate]
I am trying to play around with type deduction in templates in c++. I am experimenting with type deduction for array arguments, with the following code:
template <typename T, std::size_t N>
...
-4
votes
1answer
29 views
hexa-decimal to decimal conversion (using implicit type casting)
I think there's some problem in my vs code I am new to this coding stuff even after writing the correct code it gives me wrong results in almost every second code I write i get uncertain results Plz ...
0
votes
1answer
108 views
How do I fix an Invalid Comparator error?
MSVS 16.9.3
Win7-64
I get an invalid comparator error on the second execution of my sort comparator passed to the C++ Sort function provided in <algorithm>. I don't understand why I am getting ...
0
votes
1answer
54 views
Why there is no output from `cout` but it is ok for `printf`
To clear illustrate the problem, here is a minimal code. Why there is no output for my line cout << z << endl;? I am running it on Mac OS, compiler is Apple clang version 12.0.0 (clang-...
-1
votes
0answers
37 views
Is it possible to pull out a result from the CMD to C++ int? [closed]
Hi,
I don't know a lot about programming, but I was wondering if there is any way in C++. I can extract the result of a CMD command and then convert it to a string to later use it in c++.
I will use &...
0
votes
0answers
33 views
C++ How to register a function to receive events [duplicate]
I'm new to C++ so I'm not sure what they called to what I'm trying to achieve making it hard for me to solve this.
I like to create a class that will notify a function when a new result has been done. ...
-1
votes
1answer
40 views
problem when creating a class with a template
What am I doing wrong?
#include "String.hpp"
namespace java {
namespace lang {
template<typename T>
class Comparable<T> {
protected:
virtual int8_t compareTo(T&...
0
votes
1answer
47 views
How to compile C++ application with #include <thread> in windows (MinGW - W64) using G++? [duplicate]
I have tried compiling my C++ File with #include <thread> using G++, but it failed. Here is my source code
below:
#include <iostream>
#include <thread>
#include <windows.h>
...
-1
votes
0answers
39 views
C++ program with shared data between two functions
I have a program very similar to the one below where it is trying to use some shared data between two asynchronous functions.
#include <mutex>
class myclass {
public:
myclass() {numPackets = ...
-1
votes
1answer
99 views
Function that returns max element of an array of different types
I have couple of compare function that go something like this:
int greater_than_int(const void *a, const void *b) {
if (*(int *)a > *(int *)b) return 1;
return 0;
}
and a max function that ...
-1
votes
0answers
27 views
Filling the array created by std::vector with an own function
I have a problem with a rather basic task. I am trying to fill an array by my own function and despite the impression that I'm doing everything ok, the fuction does not work.
So there is my fuction:
...
0
votes
2answers
54 views
Map constructor with comparator
class cmp{ // simple comparison function
public:
bool operator()(const int x,const int y)
{ return x > y; }
};
When I call any stl algorithms like std::sort with an object of compare , it ...