VS Code displays ($?) { g++ test.cpp -o test } ; if ($?) { .\test } in terminal - c++

When I am running code in vscode, the text if ($?) { g++ test.cpp -o test } ; if ($?) { .\\test } always appears at the top of the terminal.
I don't know what it means.
Is this a problem, and if so, how do I fix it?
The full text:
PS C:\Users\admin\OneDrive\Máy tính\Lập trình\Bài tập C++ TTA> cd "c:\Users\admin\OneDrive\Máy tính\Lập trình\Bài tập C++ TTA\Hàm\" ; if ($?) { g++ test.cpp -o test } ; if ($?) { .\test }

Related

How can vscode display "return value" in terminal?

TreeNode* root = new TreeNode(0);
int i = root->left->val; //root->left is nullptr, so no root->left->val
cout<<i;
The code above is wrong. I want my vscode to dispaly "Process exited after 0.7621 seconds with return value 3221225477" to let me find out the mistake immediately. But my vscode return nothing like this:
PS C:\Users\ValiantHeart\OneDrive\CodeFiles\CFiles> cd "c:\Users\ValiantHeart\OneDrive\CodeFiles\CFiles\" ; if ($?) { g++ 1.cpp -o ./build/1 } ; if ($?) { ./build/.\1 }
PS C:\Users\ValiantHeart\OneDrive\CodeFiles\CFiles>

problem facing with vs code code runner for c++ "program failed to run"

i recently added code runner extension in vs code and it worked fine.but when i created a new folder the code runner didn't work as i expected.so i deleted the folder and when i used to previous folder(which used to work fine) this also didn't work.it started showing the following error message
PS C:\Users\ARAVIND SWAMY\projects\helloworld> cd "c:\Users\ARAVIND SWAMY\projects\helloworld\" ; if ($?) { g++ program50.cpp -o program50
} ; if ($?) { .\program50 }
Program 'program50.exe' failed to run: Access is deniedAt line:1 char:107
+ ... if ($?) { g++ program50.cpp -o program50 } ; if ($?) { .\program50 }
+ ~~~~~~~~~~~.
At line:1 char:107
+ ... if ($?) { g++ program50.cpp -o program50 } ; if ($?) { .\program50 }
+ ~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
so i deleated every extension in vs.code in folders and started redownloading it again but it didnt work

.gcda files don't merge on multiple runs

I have two main functions that use a common C++ class.
File1: main.cpp
#include <iostream>
#include "HelloAnother.h"
int main() {
HelloAnother::sayHello1();
return 0;
}
File2: main2.cpp
#include <iostream>
#include "HelloAnother.h"
int main() {
HelloAnother::sayHello2();
return 0;
}
File3: HelloAnother.h
#pragma once
class HelloAnother {
public:
static void sayHello1();
static void sayHello2();
};
File4: HelloAnother.cpp
#include <iostream>
#include "HelloAnother.h"
void HelloAnother::sayHello1() {
std::cout << "Hello 1!!!" << std::endl;
}
void HelloAnother::sayHello2() {
std::cout << "Hello 2 !!!" << std::endl;
}
Now I compile two executables:
clang-3.8 -o main -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main.cpp HelloAnother.cpp
clang-3.8 -o main2 -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main2.cpp HelloAnother.cpp
Now, I run ./main
Hello 1!!!
When I rerun ./main
Hello 1!!!
profiling: /media/sf_ubuntu-shared/test-profiling/main.gcda: cannot map: Invalid argument
profiling: /media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda: cannot map: Invalid argument
One second run, I get this error (above) in trying to create/merge .gcda files.
Now, If I try to run ./main2
Hello 2 !!!
profiling: /media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda: cannot map: Invalid argument
When I generate the code coverage report, the call to second function doesn't show up as if the call wasn't made.
Can anyone help me debug this issue pls? The issue seems to be related to merging of .gcda files on multiple runs, but not sure how to solve it.
I also tried clang-3.5 but with same results.
After a lot of searching and trial/error this is what works for me:
Compile first executable, run it. This generates HelloAnother.gcda and main.gcda files.
Execute lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main.info
rm -rf *.gcda; rm -rf *.gcno
Compile second executable (main2.cpp), run it. This generates another HelloAnother.gcda and a main2.gcda file.
Execute lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main2.info
Now to generate nice looking html report do: genhtml -o coverage coverage.main.info coverage.main2.info
Your problem is that you compile the shared file (HelloAnother.cc) twice and gcov fails to understand that two copies of HelloAnother.o inside main1 and main2 need to be shared.
Instead, compile the shared code once and link it into each executable:
$ g++ --coverage -c HelloAnother.cc
$ g++ --coverage main1.cc HelloAnother.o -o main1
$ g++ --coverage main2.cc HelloAnother.o -o main2
$ ./main1
Hello 1!!!
$ ./main2
Hello 2 !!!
$ gcov --stdout HelloAnother.gcno
...
1: 4:void HelloAnother::sayHello1() {
1: 5: std::cout << "Hello 1!!!" << std::endl;
1: 6:}
-: 7:
1: 8:void HelloAnother::sayHello2() {
1: 9: std::cout << "Hello 2 !!!" << std::endl;
1: 10:}
-: 11:

error: 'CFLAGS' does not name a type

This is my makefile:
CFLAGS=-Wall -g -O2
clean:
rm -f ex1
And when I run a script, for example, this one (ex3.c):
#include <stdio.h>
int main()
{
int age = 10;
int height = 72;
printf("I am %d years old.\n", age);
printf("I am %d inches tall.\n", height);
return 0;
}
I get the following error:
$ g++ Makefile.c -o makefile
Makefile.c:1:1: error: 'CFLAGS' does not name a type
CFLAGS=-Wall -g
^g++ ex3.c -o ex3
$
Please don't compile the makefile.
Use the make utility instead.
Synonyms include nmake and gmake.
The makefile should be passed to the make program or build utility.

GDB will not step into a user defined function

I am compiling some code for leftist heaps, and I want to step through my levelorder traversal function. However, whenever I reach a breakpoint at "theheap.levelorder()" and type "step", gdb passes over the code.
I am compiling with the -g flag and have tried -fno-inline to no avail. Why is this happening?
My makefile is as follows:
all:LeftistHeap.o lab10.o
g++ LeftistHeap.o lab10.o -g -o lab10
lab10.o:LeftistHeap.h
g++ -fno-inline -g -c lab10.cpp
LeftistMax.o:LeftistHeap.h LeftistHeap.cpp
g++ -fno-inline -g -c LeftistHeap.cpp
clean:
rm *.o *~ lab10
EDIT:
I have two levelorder() functions: one private, one public. i know this is probably unnecessary, but it shouldn't result in gdb acting like this.
levelorder is declared as follows in the .h file:
public:
void levelorder();
private:
void levelorder(LNode* node);
levelorder is defined as follows in the .cpp file:
void LeftistHeap::levelorder()
{
levelorder(root);
}
void LeftistHeap::levelorder(LNode* node)
{
queue<LNode*> currentLevel, nextLevel;
currentLevel.push(root);
while(!currentLevel.empty())
{
LNode* temp = currentLevel.front();
currentLevel.pop();
if(temp)
{
cout << temp->key << " ";
if(temp->lchild != NULL)
nextLevel.push(temp->lchild);
if(temp->lchild != NULL)
nextLevel.push(temp->rchild);
}
if(currentLevel.empty())
{
cout << endl;
swapq(currentLevel, nextLevel);
}
}
}