Tag c++14

[Solved] Function receiving different value than passed

At least part of the problem is that you are not understanding how operators work in C++. for(i=1;i<=n,completed==0;i++){ The expression i<=n,completed==0 has the effect of evaluating i <= n, discarding the result, then evaluating completed == 0, and giving the…

[Solved] C++ vector of strings segfault

As panta-rei correctly pointed out, it looks like you’re trying to contain a string of the form “string” + string form of (i) but you’re actually doing pointer arithmetic which is illogical in this case (you’re just passing a pointer…

[Solved] file handling I/O c++ error

You have p as some pointer. Who is going to allocate the memory that pointer points to? In C it is almost always the responsibility of the caller to allocate any buffers before the call. If you don’t want to,…

[Solved] N-Queens Algorithm using c++

The part in is_attaced in which you check the diagonals is not working. It has two basic problems, first you dont check all diagonals all rows – you just check the previous row. And, second, you are doing out of…

[Solved] why is cin/cout slower than scanf/ printf

The speed difference is largely due to the iostream I/O functions maintaining synchronization with the C I/O functions. We can turn this off with a call to std::ios::sync_with_stdio(false); By default standard C++ streams are synchronized to the standard C stream…

[Solved] Dynamic Memory allocation fault

The issue is that n keeps growing, but your array does not. This code invokes undefined behavior, which thankfully caused a segfault for you: while(ch==’y’) { n++; cout<<“Enter 1 more element: “; cin>>arr[n]; cout<<“Want to enter more? “; cin>>ch; }…