You are on page 1of 10
2or7iaia0 (C++ programming wih Visual Studio Code ‘Version 1.35 Vupdates nom avalsble Read sou the new features nd fs ny x C/C++ for VS Code (Preview) 7 (stos/igthue com/Mirorotivxcode.does/laby/mate/docsanguagescpp:m) ‘entenson fitosi/marketpacesiualituso com/erttemName=mewicode copoly) 10 (/c++ seppet fr Vinal Stato Code is provided by a Mcross CIC ‘nsble coreplattor Cand C++ development ung VS Cade on Windows Linux and maeOS. The extension i ilin preview and aur foci code editing, aviation and debugging supper for Cand C++ code everywhere that VS Code rns reer recy Sea eee ire: a ra Penk? tfyou ust want aightwsight tool 0 edt your C+ Ales. Viva Stao Code i 3 great choice but ifyou want he best pore experience for your exiting Vial Cr+ projets or aebugging on Windows, we recommend you ee 3 version of Vial Sts such a Visual Sto Commi Cte com/prodi i stusio-communty) Hfyourun inte sy sues ot have suggestions forthe Microsoft C/C=+ extension plese leases and suggestions on Gtub hips //ithub com/Micrososcede cpptoolfssus, you havent ead provided feedback please take this quick suey (p/m research nel VAVVECE) to help shape tis extension for your Note for Linx wer: The C/C++ extension works on 6tbit Linu astosthathave gb 2:18 or ater insta. Getting Started ‘Toinsl the Microsoft /Ce+ extension: + Open V5 Code + Click the extensions View icon onthe Sidebar + Seach for eve + Chick stall hen dice Reload Fes Def EEO Tee (eee eta Bor With he C/C++ extension instal, open folder hat contains your JC sourcecode VS Code wl pce varius settings fle ito& .vacode subfolder [Note:The C/C++ extension doesnot include C++ comple of debugger. You wl nee te Inst hate ool ous those lead isle on your computer Popul C++ compiler ate MinGW (hip:/ Pw mingwarai for Windows XCode ftps://Seveloperapplecom/ncode/ for macOS, and GCC (ntpsigeesnuerg on Un rake sure your compiler execute ison you plato path fr VS Cade to A ‘To-emble code compton nd navigation you willneed to generate a «_ Ifyou lke tobe able to bull your appleton with a Run Bud Tak ctloshivte}, you can adel tothe Suits grou ‘ « > Far mare informstian on aks se ntagrate with Exel Toke vi Tasks Yooes/etarak ‘Toemable debugging you wil need to generate a tauncn son fie + Navigate to the Debug viw by ccking the abu conn the Sidebar. + nthe Debug view, dckthe Configure con 4 Select chs (s02/.Lb8) (9. use GOB er LIDS or Ci> (Kndowe) {Louse the Visual Studio Windows Debuaget fom the Slee Ervonment d-opdown, ths creates Launch jan fl fo edtng with wo configurations © Cas Launch defines the proerties fr launching your speition when you stat debugging hips:i/eode.visvalstuaio.comidocsilanguagesiope 20 2or7i8/80 (C++ programming wih Visual Studio Code © Cee Atach defines the properties for attaching oa proces thats aency raning + Upsate the progr property withthe path tothe program you are bugging + Ifyou want your apotiaton to ull wren you sar debugging, ad a presaunchTask propery with he name ofthe bul task you created in tasks json (bul hl wort in the example above) Below san example using the MinGW GOB debugger ‘ Configurations”: [ « snares "egy Lane, “qrogran’: "Swokspaceseat)/9.040", es": Ce setoptcentty": false, coals “S(aorkpacehaot)", enviroment": (Ty ‘nsoebagger2ath": "C:\\ninge\ Binge" Setupcomancss ( « > » > Tolear more, see Coniguinglaunchjson for C/C++ debugging tosi/gthuh comyMicrosofyvscode-captolyblob/master bunch ma tfyow ate debugging with GO on Windows, see Windows Oebugging wth GOR Editing Code Cade Formatting ‘he C/C++ extension fr Visual tule Code suppor sourcecode formating sing clang orm tps //dang lm ovg/docsClangrarmath which since with ‘You can format an enti le with Format Dociment (shi stoater joes the current selection with Format Selection (ctriak tele negli context men, You ‘an algo configure autosormating wth he following stings Vdocs/getsartesisetings! + cep.clang format fornaonsave =to fmt when you save your fil + settor.toreatonype 0 format a8 you type eggered on the 5 characte 2 default he clong-format sys set 0 “le which means it looks for» clang-forat fl insice your workspace the .clang-ormatfles found formating is pple according tothe stings speed nthe le Ino. .clang-fornt file is found in your workspace formatting fe appli ated ona deft syle spaced inthe tp. clang format falibecstyle sting Udocs/getstarted/satings) instead. Curent he default formating sys Visual Studio’. Using "Visual Sudo" formatting ensures that source code formating wl be comin both VS Code and VewlStutio Commun “The Visa Sts cang-fomt shes not yet an ofl COTS cang-format ase but implies the following lng fermat settings: Usetab: (WS Cade current setting) Tnaenthidth: (05 cose current setting) Iryou'd the to use a fren version fclang-format than the one that sis with he extension you can use the Ce. clang format oath setting \Wdocsigetstaed/sevings) and sti value to the path where the dangformat binary isinstalle, For example onthe Windows pliform “Cp.etang_fornat_path": °C2\\Pgran Fes (246) \LLIMbin\\elang- format exe" Fuzzy Auto-Compbete Funy auto-complete i powered by an enhanced tag-pase approach. Ahough suggestions ate not based on semantic nays of your code, hs feature provides 3 vider stcion of matches than the sngle-le nelisene experience provided tod In paral this features capabltes give 2 good experience for C code Navigating Code hilps:i/eode.vievalstucio.comidocsilanguagesiepp ato 2or7iaia0 (C++ programming wih Visual Studio Code powered by tgs sored nan ofine database of symbol information With the C/C++ extension installed, this taba is generated whenever 3 fle contining Cot source cose fle isloaces into VS Code. The platform incctor (Win? inthe figure below! tars ed anc appears nett a hm icon whe the 35-paser is generating 2 Ti "32 hen the pltform indicator retune to is normal appearance. the svrce coc symbole have been tagged inthe ofne database and sourcecode navigation features Spectying Adltonal Induee Decors for Better Symibal Suppo ‘To protide th bet experince, the C/C1 + extension for VS Cede needs to know where can find wach head file raferencedin your code By defsul, the extension searches the curant ure rectory ts aub-airectoris, and some phiform-pecic locations, Ha refaranced header file cant be found VS Code paye3greon squiggle underneath exch Finca directive that references Te spect adtional inde rectors tobe che pce your csr ver any fncude dectve that dplays teen squiggle then ck the lightbulb action when I sppears. This opens the fle cpp_proereies.jsn for eting here you can spec adional include rectors for exc platform configuration indus by To search fora symbalin the curent fle, press ctravsnsee then enter the name ofthe symbol you'e looking for. Ais of potenti matches wl appear and be ‘kare a8 you type, Choose fom thet of matches to navigst ots location hilps:i/eode.vievalstucio.comidocsilanguagesiepp ano 2or7iaiao (C++ programming wih Visual Studio Code # guano — “To seareh fora symbolin the current workspace sr by pesing Cele iste, hen enter the name ofthe symbol Ast of potential matches wil appear as before. you choose a match tht was found ina fle tha’ not sesdy pen, efile will opened fore nvigating ta the mate's leaton oo [Ateratvaly you can search for symbols by accessing these commands though the Cammand Pate you prefer. Use Quek Open (c2n1?) then ener the“ ‘comenand to search the cute fl, ofthe" conmand to seat the curent workspace, cteshi 9 and CARLA arejist shortcuts forthe" and#" commands, respectively so everything works the same. ‘You can take» qucklook st how 3 sys was defines by sing the Peek Definition feature. This etre displys fw nes of cade nea he cefintion inside 3 peek window so you can ake aloo without uigating away fom your cure cation. Topesk ata symbots defo place you curr onthe symbol anyuhere its sed in your soutce cade and then pres Aleea2, Alternatively you cn choose Pek, Definition rom the contest mens ight-c then choose Pek Defic). hips:i/eode.vievalstudio.comidocsilanguagesiopp 5110 2or7iaiao (C+ programming wih Visual Studio Code peeeeee cere. aves rraeerrn cea Current, he C/C++ extension doesn parse code in way that helps it astinguish between competing definitions based on how the symbolis used. These compating sitstions hen this happens each ofthe comping defntons ae Fred inthe right-hand side ofthe peek window wth the source cage af the current selection spayed on hele With the peek window open you browse the tof competing definitions to find the one youre Interested in. you want to maga to the locaton of one of the efintions jst double-clek the defini you're intereset i by duble-iekng anywhere inthe soutce code displayed on theet-hand ide ofthe peek window Ge te Defnton You an aso quity navigate to where a symbols defines by sing the Goto Denton feature way, you can choose Goto Defnon fom ‘he contest menu figh-clk then choose Go to Deion When there's oly one defnton ofthe symbol, youll anigate dite tas lection, there the competing definition are cigplsyed ina peek window a described in the previous section an you have to choose the cefnton that you want 9 9%. Debugging ‘Aker you have setup the basis of your debugging enviconment s specifi Getting Stated Ydocs/languages/eppe ge shout debugging C/C++ inthis section ng-started, you can lam more details 1S Code supports he following debuggers for C/C++ depending onthe operating sytam you a using + Une cos + macOS: 108 or GDB + Windows: the Visual Studio Windows Debugger o GDS (using Cygwin or Mincy Windows Debvaging with GDB ‘You ean debug Windows application rated wsing Cygwin or MinGW by sing VS Code. To use Cygwin or MinGW debugging features, the debugger path muse set manual in the lunch configuration aun. en. To debug your Cygwin or MinGW appcaton ads the aibebuggerPath property and sets value tthe location of ‘he coresponcing gdb axe for your Cygwin or MinGW environment niveneggeenn's “ee V\ainge\ Bini. exe™ yawin/tinGW debugging on Windows supports bath tach and launch debugging scenarios Condtonal Breakooints Conditional breakpoints enable you to break exeaton on a particu ne af ode ony when the valu ofthe conn is true Tost condtonal brekpoin ght= lick onan exsting breakpoint and select Edt Braakpoint This opens. smal peek window where you can ene he conton that must evaluat to tue inorder for he breakpoint tobe hit during debugging, hilps:i/eode.vievalstucio.comidocsilanguagesiepp eto 2or7raia0 (C+ programming wih Visual Studio Code a Inthe ecto, condtional breakpoints are inccates by a breakpain symbol hat asa black equals sign inside oft You can pace the cursor over a conditional breskooin to show ts conion uncon Beeaepoins Function breakpoints enable you to break eacution atthe banning of function istad of on a particu in of code, To an a futon breakpnt onthe Debug liccnsde the Brakpoints section, thn choose Addl Futon Breakpont an entrthe mama of he funtion on which you want to break execution, ane VS Code supports expression evaluation in several context: + Youcan type a expres. nto the Watch section of the Debug panel anit willbe evant each me breakpoint shit + You can sype an expression into the Babug Console ard willbe evaluated only onc. *+ You can evaluate any expression that pears in your code while you're stopped at a breakpoint Note that expressions inthe Watch section te effect nthe apolation being debugged an expression that mete the value of vibe wl md that vrable fr the duration of the program, Mulistmeaded Debugging ‘The CiCr+ extension for WS Code hs the aity to debug rult-tveaded programs. All treads and thelr cl tacks appear in the Call Stade section: rnp Debugging The C/Cé-+ antansion for VS Cade algo has the ably to dag memory dumps. Te debug a memory dump, open your Iaunch jan file and add the coreougrath for {GDB or L106) or aupoats forthe Visual Studio Windows Debugger property to the C+ Launch cairn, se Rs value tobe a sing containing the pth tthe rremoty dump, Tis wl even work for 85 progiams being debugged an an x84 machine -divanal Symbol Ihre ae aédona directories where the debugger cn find symbol les (for example, pa fs forthe Visa Scio Windows Debugger, they can ba specie by aaing the edetionansouasearchoth for C8 or LLDB) or syrtlSearenpath (or he Visa tudo Windows Debugger, “eaPath": pathy to/ symbols /anotner/pat/to/ symbols” “symorsearcnpaty: "C:\\gatn\\tesyaboisiC:\Narather\\paen to\isimbels source The source ile lection canbe changed if the source les ae not located in the compton locaton. This done by simple replacement pas aed inthe ourettlonap Secon, The st match inthis stl bused, For ample: hilps:i/eode.vievalstucio.comidocsilanguagesiepp m0 2or7i880 (C++ programming wih Visual Studio Code SsourceFsieaps ( Paute/ gent. aMjsi/gce-48-4.8.4/bule/s686-2inue-gn/ Lbstdert-¥3/snehade/686-Linu gna": “/usr/SneLud/L6-Snae yoatey cent, 8-Mi}ST/ece-48-4.8.4/t6/3686-Dinox-gu/ibstéces-w3/tnehude™: “/use/nelude/e+4/4.8° alee, (608, {1.8 and Nal Commands (6DB/LLOB) Forthe Cie (08/.tb8) debugging envzonmient, you can execute GDB, L.DB and MI commands dec through the debug console wth the este command, but be ‘careful emecuting commands direct in the cebu consoles untested an might cath VS Coden some ees, Other Debugging Features + Unconional breakpoints + Watch window + callstack For more information on debugging wit VS Code, se this introduction to debugging in VS Cos Udocsedtordebuggingh Known Limitations Symbols ane Coxe Navigation A platforms: + Because he extension does’ pase fonction bosies, Pek Definton and Goto Defniion don’ work for symbole defined inside the body of function Debvaging + 68 on cygwin and MinGW cannot break a running process. To set a breakpoint when the application is running {net stopped under the debugge), ote pause ‘the appliation beng debugged, press ceric inthe appliation’ terminal + 608 on Gygwin cannot open core umes. + 608 ness elevated permissions to attach toa process When using attach to process you need to provide your passed before the debugging Session an begin mac05 + uve: © When dugg wth LLDB, fhe Teminal window is closed while in break mode, debugging does nat soo, Debugging can be stopped by pressing the Stop baton © When deaugging i stopped the Terminal window i not desed © Addins! manual instal steps nee to he completed to use GDB on macO. See Manual instalistin of GOB for OS Xin the README Uhtpsy/markaplacevisubtudo conyitens?temName=nsancode

You might also like