Unable to debug c++ program with class implementation - c++11

I am trying to setup debugging environment in visual studio and I hope I was successful in doing it,because when I am trying to debug a normal math c++ program then my break point is hitting(or first line of code as default breakpoint) but when I am trying to debug the main program with class header file name included in the main program(i.e with class object or class implementation) then my breakpoint are not hitting. Any help where I am going wrong??
#include <iostream>
#include "Sales_item.h"
using namespace std;
int main()
{
cout<<"hello";
Sales_item item1, item2;
cin >> item1 >> item2; // read a pair of transactions
cout << item1 + item2 << endl; // print their sum
return 0;
}
This is showing in cppdgb console:
C:\Users\admin\Documents\cpp>c:\Users\admin.vscode\extensions\ms-vscode.cpptools-0.26.1\debugAdapters\bin\WindowsDebugLauncher.exe
--stdin=Microsoft-MIEngine-In-w2a4a5fw.4hb --stdout=Microsoft-MIEngine-Out-q2oc4jsv.b14 --stderr=Microsoft-MIEngine-Error-rlvf2qhl.2bw --pid=Microsoft-MIEngine-Pid-3fayxkbu.ji4 --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi

Related

Xcode doesn't let me edit files

Newbie here. I'm trying to learn Xcode and I've written a simple code here that takes a string input from an Input file and is meant to print it out to an Output file. Easy stuff, if it wasn't that I cannot figure out why Xcode isn't letting be edit Input and Output files from within the app. Here's the code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream Input;
ofstream Output;
Input.open("Input.txt");
if(!Input)
{
cout << "Input file not found" << endl;
return 1;
}
Output.open("Output.txt");
if(!Output)
{
cout << "Output file not found" << endl;
return 3;
}
string prova;
Input >> prova;
Output << prova;
return 0;
}
To make absolutely clear what I mean the editor doesn't let me edit Input files, I've uploaded a video here, hope it helps. Thank you.
Specs: Xcode Version 11.4 -> can't update it to the last version because my Mac is too old / Mac OS Catilina Version 10.15.7

why the output of the auto variable displays something not related to type?

I tried a example on Auto for variable initialization and STL in C++. For normal variable, type was printed using : typeid(var_name).name() to print i (integer) / d(float) / pi(pointer) which works fine.
But while working on STL,
`#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<string> st;
st.push_back("geeks");
st.push_back("for");
for (auto it = st.begin(); it != st.end(); it++)
cout << typeid(it).name() << "\n";
return 0;
}
`
which gives output like,
`N9__gnu_cxx17__normal_iteratorIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt6vectorIS6_SaIS6_EEEE
N9__gnu_cxx17__normal_iteratorIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt6vectorIS6_SaIS6_EEEE`
and I am unable to understand the output logic behind it, can anyone explain why it is giving output like this? and thanks in advance
That's the "name mangled" version of the name of the type of it. typeinfo::name() is not required by the standard to return a name in human-readable format (a shortcoming IMHO) and GCC doesn't do so.
To get the actual, human-readable name, you need to call the abi::__cxa_demangle() function provided by GCC, but note that this is non-portable so if your project needs to work on different compilers you'll need to wrap it appropriately.

Error: unable to open primary document entity

I'm trying to parse an xml file(I've got the schema definition in xsd as well) in my c++ program using xerces library. To get things started I've written a small program, where I just initialise the std::unique_pointer with the xml file. I get the following error if I use an std::string object containing the xml file while initialising whereas the program runs fine if I use the xml file directly for initialisation.
The main program is as follows:
#include <stdio.h>
#include <iostream>
#include "ShDataTypeRel15.hxx"
#include<fstream>
#include<string>
using namespace std;
int main (int argc, char* argv[])
{
try
{
fstream t("/home/vishal/UDA_XML/ShDataTypeRel15.xml", ios::in);
stringstream buffer;
buffer << t.rdbuf();
std::string xml_file = buffer.str();
std::unique_ptr<tSh_Data> Shdata(Sh_Data(xml_file));
}
catch (const xml_schema::exception& e)
{
cout <<"Exception caught"<<std::endl;
std::cerr << e << std::endl;
return 1;
}
return 0;
}
When I replace std::unique_ptr<tSh_Data> Shdata(Sh_Data(xml_file)); with std::unique_ptr<tSh_Data> Shdata(Sh_Data(argv[1])); then the program runs fine(I provide the path to the xml file as command line input.)
I get the following error:
Exception caught
:0:0 error: unable to open primary document entity '/home/vishal/UDA_XML/<?xml version="1.0"?>
The above error statement is followed by the xml file.
Problem was solved after I stored the location of my XML file in the string object instead of the whole content of that XML file in it.
i.e.
Now my std::string xml_file = path_to_xml_file;

Visual Studio Intel Threading Building Blocks DLL error

I am using an example of Intel TBB code I found on SO:
#include "tbb/blocked_range.h"
#include "tbb/parallel_for.h"
#include "tbb/task_scheduler_init.h"
#include <iostream>
#include <vector>
struct mytask {
mytask(size_t n)
:_n(n)
{}
void operator()() {
for (int i=0;i<1000000;++i) {} // Deliberately run slow
std::cerr << "[" << _n << "]";
}
size_t _n;
};
struct executor
{
executor(std::vector<mytask>& t) :_tasks(t)
{}
executor(executor& e,tbb::split) :_tasks(e._tasks)
{}
void operator()(const tbb::blocked_range<size_t>& r) const {
for (size_t i=r.begin();i!=r.end();++i)
_tasks[i]();
}
std::vector<mytask>& _tasks;
};
int main(int,char**) {
tbb::task_scheduler_init init; // Automatic number of threads
// tbb::task_scheduler_init init(2); // Explicit number of threads
std::vector<mytask> tasks;
for (int i=0;i<1000;++i){
tasks.push_back(mytask(i));
}
executor exec(tasks);
tbb::parallel_for(tbb::blocked_range<size_t>(0,tasks.size()),exec);
std::cerr << std::endl;
return 0;
}
The code builds fine, but when I go to run I get the error:
The program can't start because tbb_debug.dll is missing from your
computer. Try reinstalling the program to fix this problem.
I think this is probably the path I need to set somewhere within VS2012:
C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\ia32\tbb\vc11
because it contains tbb_debug.dll.
Where does this path need to be set?
EDIT: I tried setting in the "Executable directories" path section but that didnt work.
In solution explorer, right click the project and open "Properties"
Open "Configuration Properties" -> "Debugging".
In the "Environment" line, add "PATH=C:\Program Files (x86)\Intel\Composer XE 2013"
Make sure "Merge Environment" is set to "Yes".

Phantom syntax errors in Visual C++ 2010 Express

I just started learning C++, and I'm getting weird 'phantom' syntax errors in Visual C++ 2010 Express.
There are red lines under seemingly random pieces of code, and when I hover my cursor over them it shows errors that seem to make no sense at all. However, when I hit F5 the program compiles and runs successfully.
It's hard to learn C++ like this because I can't quickly distinguish between real syntax errors and 'fake' ones.
The syntax errors:
http://i.stack.imgur.com/O0UbD.png
The program:
#include <iostream>
#include "conio.h"
#include "windows.h"
class test2
{
public:
int i;
};
class testc
{
public:
test2 hi;
};
int main()
{
testc hello;
hello.hi.i = 23;
std::cout << hello.hi.i << "\n";
system("pause");
}
I reinstalled entire Visual Studio, not just Visual C++. Now it works correctly.

Resources