spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » C++ » Page 4
Analysing wave header
Here are a bunch of links that helped me out a ton when I was working on this kind of a project. https://github.com/visore/QAudioCoder http://qt-project.org/forums/viewthread/6899 http://doc.qt.digia.com/qt-maemo/demos-spectrum-app-wavfile-cpp.html http://fledisplace.com/QtMultimediaExample2.html I did find a typo in one of the examples, it wasn't reading one of the parameters with the correc

Categories : C++

how to deal with map of map?
You want to make a more descriptive typedef than ii, but specifically you just want to add a new key-value pair into the map: m[s1].insert(std::make_pair(s2, t)); Or if you want to split it up for clarity: ii& submap = m[s1]; submap[s2] = t; Or, if C++11 is available to you, exactly what you expressed in your question: m[s1] = {{s2, t}};

Categories : C++

Mix CPP OpenCV / Main program C
Ok i solved my problem using a wrapper : I've made a header file like wrapper.h and wrapper.cpp. in the wrapper.h i got : extern "C" my_function_through_wrapper(); in the wrapper.c i got : #include file_where_my_function_if.h extern "c" { my_function_through_wrapper(){ my_function(); } } And that's it ! Indeed i've made and interface between the real mangling CPP and the C c

Categories : C++

Cannot understand if this is circular dependency or Clang
Well, this doesn't completely tell you what's wrong, but hopefully will point you in the right direction. The problem is that quaternionbase_assign_impl doesn't support 3X1 matrices, it seems. (Unless there is other code that is getting into the translation unit somehow.) There is a forward declaration of it: template<typename Other, int OtherRows=Other::RowsAtCompileTime, in

Categories : C++

Binary search equivalent for `find_if`
I believe you're looking for std::binary_search or std::lower_bound.

Categories : C++

Use of std::regex_iterator according to CPlusPlus.com
What do you mean with "if rend is never initialized"? Clearly, std::regex_iterator<I> has a default constructor. Since the iteration is only forward iteration the end iterator just needs to be something suitable to detect that the end is used. The default constructor can set up rend correspondingly. This is an idiom used in a few other places in the standard C++ library, e.g., for std::istr

Categories : C++

C++ Erasing element from a vector of pointers
You're deleting the account from a copy: std::vector<T*> getDatabase () const; std::vector<Account*> db = m_acctDb.getDatabase(); You need to delete from the actual database, so you want the usage to be: std::vector<T*>& getDatabase (); const std::vector<T*>& getDatabase () const; std::vector<Account*>& db = m_acctDb.getDatabase();

Categories : C++

Getting out of scope error with dynamically allocated array
If you declare the variable inside the try block then it's only accessible there. You can work around this by moving the declaration outside of the block. int *newArr; try { newArr = new int[els]; } catch(const bad_alloc &) { die("Alloc Failure"); } for (int i = 0; i < els; i++) newArr[i] = a[i]; Or by moving the rest of the code inside the try. try { int *newArr = new

Categories : C++

tuple - reasons for a separate header
There is a tension between having fine-grained headers and having just one header (e.g. <all> was proposed). Since compilers have to process the tokens within each header and some internal data structures also grow with the declarations seen (especially when the declarations use the same name like operator<<()), there is a compile-time trade-off. The original implementation of tuple<

Categories : C++

Boost with eclipse cannot find thread library
Specify the library without the lib prefix (which is the UNIX convention): g++ "-LC:Boostoost_1_57_0stagelib" -pthread -o MyThread.exe main.o MyThread.o -libboost_thread-mgw49-mt-1_57 There's even a chance that (with the help of some standard convention symlinks) you could just say -lboost_thread. PS Don't forget to use -pthread as well

Categories : C++

Winsock ~ Creating an UDP Listener (Multiple vs 1 socket)
Unlike TCP, UDP is connection-less, and as such you don't need to create separate sockets for each party. One UDP socket can handle everything. Bind it to a local IP/Port and call WSARecvFrom() once, and when it reports data to your IOCP you can process the data as needed (if another thread if needed) and then call WSARecvFrom() again. Each time new data arrives, you have to look at the reporte

Categories : C++

Os X Yosemite Qt drag and drop file name bug
To apply the patch, you would need to download the Qt Sources (ex. use git) and then add the lines needed to retrieve the filepath instead of the fileId using the: QUrl::fromNSURL([url.toNSURL() filePathURL]); method. Here is the part where it should be added: Patch Code When you did this, you need to build Qt and build your project with this patched version to take use of the changes you mad

Categories : C++

Const char* not assigning properly?
The problem is the value returned from split76 is temporary and is destroyed after the assignment has completed. Any attempt to access it after that results in undefined behavior. If you need to store a pointer to the string buffer you can create local std::string to hold it an ensure it lives long enough to be used. std::string encodedFile(split76(readFileToBase64("C:\Users\thrymgjol\code\emailt

Categories : C++

Decimal to binary/hex using arrays
binary The problem is after the first loop, i is one greater than the last index. Just for example, say you enter 1: the do...while loop is entered, the digit 1 is put in array index 0, then i is incremented to 1. Then, in the second loop, both indexes 1 and 0 are printed. You can solve this by decrementing i before entering this loop: i--; while (i >= 0){...} You should be doing something

Categories : C++

Simple error checking in file output
When writing chars there aren't too many things which can go wrong. The only error which may occur is that the stream's std::streambuf reports an error in overflow(). This adequately tested by your test. That said, successfully buffering characters doesn't mean that writing the buffer will be successful. To test for a successful write you'll also need to test if fout.close() is successful! The imp

Categories : C++

Adding second argument in a C++ function prevents OpenGL from drawing?
It could possibly be a memory corruption bug, and by adding the extra parameter you are subtly changing the layout of data in memory and causing the bug to have a visible effect, where before you were getting away with it - i.e. you were still overwriting memory, but happened to be overwriting something unimportant. Normally your function would be removed by the compiler because it does nothing,

Categories : C++

C++ stringstream error handling
Once a stream moved into fail state, it will stay in fail state until gets clear()ed. That is, you need to do something like this: if (ss.fail()) { std::cout << "This is not an integer "; ss.clear(); // ... } Also not that just writing to a string stream does not replace the string stream's content! to replace the content of a string stream you can use the str() method: ss.s

Categories : C++

STL set_intersection runtime error
You are trying to write objects to an empty vector. You probably meant to use std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v_in), [](const Mclass& arg1, const Mclass& arg2) { return (arg1.id < arg2.id); }); Note the addition of using std::back_inserter() to the output range. Also, as I

Categories : C++

another vector vs dynamically allocated array
There shouldn't be a performance difference between vector and a dynamic array, since a vector is a dynamic array. The performance difference in your code comes from the fact that you are actually doing different things between the vector and array version. For instance: std::vector<int> primes(primes_count, 0); for (auto i = 0; i < max_prime; i++) { if (is_prime[i]

Categories : C++

"Ambiguous resolution" error from selective constructor inheritance
The second candidate is probably the implicitly-defined copy-assignment operator, which is not shown in the source code so the compiler points to the class itself. Your Long class has an implicit conversion to various integer types that are convertible to bool and those types are also convertible to Boolean, and both of those types can be assigned to a Boolean, so the compiler doesn't know which

Categories : C++

Setting up eclipse in OS X (C++) ERROR: launch failed, binaries not found?
SO I solved my queries, here it goes: I realised that I first had to build my project once(just once) and then running it would be enough I still got the same error launch failed, i realised that eclipse could not locate the binary file that was built, I tried indicating the file directly,did not work, but what worked was setting the eclipse Parser as the mach-o-parser instead of the default elf

Categories : C++

Error compiling a custom container for boost spirit
I'd simplify this by /just/ not treating things like a container and not-a-container at the same time. So for this particular situation I might deviate from my usual mantra (avoid semantic actions) and use them¹: Live On Coliru template <typename It, typename Skipper = qi::blank_type> struct grammar : qi::grammar<It, MyContainer(), Skipper> { grammar() : grammar::base_type(start

Categories : C++

How to renew time in a programme in c++?
The clock(3) function computes the processor time (in µs generally). You want the real elapsed time. Use time(2). On Linux, read time(7) and consider using clock_gettime(2) with CLOCK_REALTIME (or maybe CLOCK_MONOTONIC). Generally, time measurement is often operating system specific (even if time & clock are in C99). If you have a C++11 implementation (e.g. g++ -std=c++11 -Wall with a rece

Categories : C++

Sort items in a QListWidget by their checked state
The easiest option is probably to create your own QListWidgetItem-derived class, with an alternative implementation of less-than operator. I.e., something along the lines of: class MyQListWidgetItem : public QListWidgetItem { public: // TODO: provide implementation of constructors virtual bool operator< (const QListWidgetItem & other) const { // if check st

Categories : C++

Why ISO C++ forbids returning arrays?
Beside the fact that the standard doesn't allow it, and the historical reasons that could explain it, the issue is syntactic: Imagine it would be permitted : how would you distinguish the naming of the whole array, vs the array address, vs a single element: auto fnReturningArray() { int a[3] = {0, 1, 2}; return a; // what is meant here ? the address of the array ? or the wh

Categories : C++

toString(): numbers in JSON
It is explained there is a double value in QJsonValue object. A quick try confirms it won't convert to string for some reason, though it converts to 64 bit int with the casting. QJsonValue jv((double)9999960902); qDebug() << jv.toString(); qDebug() << jv.toInt(); qDebug() << (qint64)jv.toDouble(); And the output is: "" 0 9999960902

Categories : C++

C++ recursion example explanation
Well, you call with 123 as n, the function executes the statement: if (n < 10) // its false, so it continues with else: else { recursion ( n /10 ) // recursive call n/10 = 123/10 = 12 (as it's int) ... It will continue like this, recursively calling with n being 12 recursion (n/10) // second recursion call n=12, so n/10 = 1 then the function is executed, with n bein

Categories : C++

C++ template specialization in different dll produces linker errors
I know you said that you dont want to modify the header since it could break the third party library updates, but the header that the template is defined in is not set up correctly. Hopefully you can get your vendor to modify their headers to be more import/export friendly. The goal: Define (export) a template specialization in a dll/so and then use (import) that specialization to your exe. tes

Categories : C++

Process exited with return value `3221225477 - compare chars or next_permutation`?
Following may help: std::string get_alphabet( const std::string& n1, const std::string& n2, const std::string& sum) { std::string res = n1 + n2 + sum; std::sort(res.begin(), res.end()); res.resize(std::unique(res.begin(), res.end()) - res.begin()); return res; } std::array<unsigned int, 256u> get_dico(const std::string& alpha, const int (&d)[

Categories : C++

C++, Math exponents
2(pow n) may be written 1 << n or if you want to compute yourself the power of two: // compute manually (1 << n) int power2(int n) { int res = 1; for (int i = 0; i != n; ++i) { res *= 2 } return res; } Your sum is in fact power2(n+1) - 1, so you may simply write: std::cout << ((1 << n + 1) - 1) << std::endl; or std::cout << power2

Categories : C++

How do I transfer some data from one node to another in C++ Linkedlist Queue?
You are allocating nodes with new and deallocating them with free. At least that's one of the bugs, there might be more. Try stepping through your code with a debugger. note; new goes with delete, and is preferable in C++ malloc goes with free and is C-style

Categories : C++

How to set a breakpoint on a DLL in Visual Studio?
Phew, that is quite a requirement you have. But to be honest, that might be something really usefull, even for other scenarios. The most easiest way I think you could achieve this is using WinDbg and setting breakpoints there. With WinDbg you could do something like this (assuming your image is named myplugin.dll): Open WinDbg File -> Symbol File Path (add path where the .pdb for the plugin is)

Categories : C++

OpenGL selective offscreen render to one of 2 textures in one fragment shader
Let's get to question 2 first: Where is my mistake? How do i prevent objectid block to write to out_color GL simply does not work that way. The rasterizer produces fragments, and your fragment shader has to determine output values for all of the render targets you have attached - or it can discard the whole fragment, so that no oupt of it is ever written to the framebuffer. If you do not e

Categories : C++

C++ std::sort custom compare function referencing to another list
isPointsVisitStartPrior is a member function, this cannot be used directly in sort. You have to either use a global function or a function-object. If you have access to C++ 11 features, you can use a lambda: std::sort(route2.getVisitedPoints().begin()+1, route2.getVisitedPoints().end(), [&](int i, int j){ return isPointsVisitStartPrior(i, j); }); You can also make a functor object with a

Categories : C++

How can I display images on the output screen using ASCII code in C++?
Well, the first option is to find another online converter which gives you a raw, copy-able, output. In that case you can use your approach. The second way is to build an ascii converter yourself. The way I think the online tools convert an image into ascii characters is the following: Build a table with relative brightness, so: space is 0 brightness, 8 = 60% brightness 0 is 80% birghtness is

Categories : C++

Why it doesn't show me the greatest common divison?
Replace a==a-b with a=a-b. Replace b==b-a with b=b-a. The operator == is comparison, it doesn't modify its arguments. The operator = is assignment, it modifies its left argument to the value of its right argument. Replace cout<<"cmmdc=",a with cout<<"cmmdc="<<a, otherwise a won't be printed.

Categories : C++

QML ComboBox item DropDownMenu style
The current public APIs does not allow customization of the drop-down menu as stated here. Qt 5.4, i.e. Styles 1.3, just introduced some properties to customize fonts and text (docs here) but still no public access to drop-down customization. Also, the example provided in the link does not work with the newer versions of Qt. Here is a modified version I've tested with Qt 5.3, Qt 5.4 and Qt 5.5 (

Categories : C++

Open a QFileDialog over a QQuickItem
Just use the QML version, it is absolutely the same dialog you will get from the QWidget based dialog. The only thing you will gain from using a QWidget based dialog is you will make it backward and you will drag several MBs for the Qt5Widgets library. Whatever you think you might be gaining from wanting to do that, it will not be worthy the effort to do it. The old QtQuick1 offered a proxy compo

Categories : C++

Calculating pow with doubles gives wrong results
You're just hitting rounding errors. There's nothing you can do about this, except revert to an integer-based approach whenever the inputs are integers. You could condition on whether the inputs are integers, and if so then use integer arithmetic; if not, then use doubles. But using exp and log will always introduce rounding errors, so you can't expect exact answers with that approach. More prec

Categories : C++


Recently Add
Returning the actual value of maximum of absolutes of variables
Microsoft c++ optimizing compiler has stopped working
Overloading operator[] changing value
what does the printf/snprintf format character %N do? (not %n)
Eigen and C++11 type inference fails for Cholesky of matrix product
Qt KeyPress Event on QlineEdit
Any reasons to look at alternatives to inheritance / polymorphism?
Cannot cast the structure pointer to char pointer in c++
Changing a C/++ OpenCV program to CUDA from video stabilization program
c++ change of coordinates (Pixels 1920 x 1080 to 640 x 480)
WinAPI SetSystemCursor and LoadCursorFrom - how to set default cursor?
Multiple clients in c++ server
avoid specifying redundant template parameters which contain templated function pointer
How to obtain mp3 audio packets for streaming in C/C++
How do I search for an element from each node in C++ using queue?
Difference between private static members and having them in the cpp file
Is the size of built-in datatypes in c++ managed on source code level?
Deleting elements dequeued using "top" from priority_queue c++
C++ Ordering the names of a scoreboard
QColor hsl hue precision
cannot read the text file properly anymore
g++ 4.8.* std::chrono Undeclared
How can I make a 'const tm*' from a 'const tm&'?
Can clang-format align variable or macro assignments in columns?
Obtaining First and Last Charsof Each String From A Vector of Strings
boost filesystem canonical path is not valid after conversion to const char *
SIGSEGV, Segmentation fault
Is there a way to detect if a primitive argument is variable size?
why can I pass a reference as an argument to a constructor's pointer parameter?
Which compiler flag am I missing in my build on the so file?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.