• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Visual studio code newbie cant debug its first program

Joined
Aug 12, 2017
Messages
60 (0.02/day)
System Name FREQUENCY
Processor I5 4570 3.4 GHZ
Motherboard ASROCK Z97 ANNIVERSARY
Cooling STOCK INTEL
Memory HYPERX DDR3 1866MHZ
Video Card(s) MSI 750TI OC
Storage SAMSUNG 120GB SSD
Power Supply CORSAIR VS550
Mouse GM200 TURBOX
Keyboard CMSTORM DEV
Software WINDOWS 10
First, you should learn how to attach images to the forum instead making people click on links... Let's start with that before something more advanced. :)
 
uObvZxfnTCyORXV0egYkMw.png
if thats the case
 
If you are declaring your Main function as an integer, should it not have to return a value?

It has been a while since I have done C/C++, but should it not return zero at the very end to let the operating system know to stop execution?
 
It does not have to. It is a special case - if main does not return anything explicitly, it returns 0.
Remember that there is no such rule in C - main will return junk.
 
uObvZxfnTCyORXV0egYkMw.png
if thats the case

You can always put your code in [code] [/code] BB Code as well.

Example:

[code]
#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World!";
return 0;
}
[/code]


Adding the above will display like what's below. This will help other users when trying to debug your code or help out.

Code:
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!";
    return 0;
}
 
Last edited:
Code:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string name, Lname;
    int age;

    cout << "Enter your first name:  ";
    cin >> name;

    cout << "Enter your last name:  ";
    cin >> Lname;

    cout << "Enter your age:  ";
    cin >> age;

    cout << "\n" << name << " " << Lname << " is " << age << " years old." << "\n" << "\n";

    system("pause");

    return 0;
}

I use Visual Studio 2017 in a Windows environment and I got your program to work making some minor modifications.

The biggest change was I always thought you had to include the string header whenever using strings. I also think that using cin with strings become more stable with the header included.
 
Last edited:
Thank you all for your posts. Any idea how can i fix?
upload_2017-9-25_16-39-36.png
 
Did you check to see if the path is correct? Try opening "e:\VSCODE PROJECTS\HELLO WORLD\" to see if the HW.ccp file exists using explorer to verify.
 
Managed to make a small progress,now i got this.
upload_2017-9-25_17-26-57.png

the code is (launch.json)
Code:
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "E:\\VSCODE PROJECTS\\HELLO WORLD\\HW.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true
}
]
}

main program
Code:
#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World!";
return 0;
}
 
Back
Top