C snippet Visual Studio 2019
I am having trouble adding a snippet to VS. All of the tutorials out there are for c# and c++.
Please help.
I want to have a snippet where I press 'C' and then this comes up:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
return 0;
}
See also questions close to this topic
-
If user inputs "sum(x,y)" how can I get x and y as doubles
I am writing a simple calculator program such that the user is entered into the programs own console environment. Each new line starts with a $. User will enter commands such as '''sum(x,y)''' '''mul(x,y)''' etc. and the program will take x and y as doubles and execute a function i.e. '''double mul(x, y){return x*y)''' and display the returned value.
I have gotten it to correctly identify the command based on matching the first three characters in the string.
I cant seem to read the numerical values correctly no matter what I do. Any suggestions are greatly appreciated!
The Code below is from main()
printf("%s", " $ "); fgets(input, sizeof(input), stdin); sscanf(input,"(%d,%d)",&arg1,&arg2); if(strstr(input,"sum")){ //char *starting_pos = strchr(input,dlm); //int position = (starting_pos == NULL ? -1 : (uintptr_t)starting_pos); //arg1 = input[position + 1]; //arg2 = input[position + 3]; printf("DEBUG: arg1 is %d arg2 is %d\n", arg1,arg2); double output = sum(arg1,arg2); printf("DEBUG: Output should be: %d\n", output); printf("%d\n",output); }else if ...
The commented section is the remnants of another way I was trying. If anyone can tell me what the right way to do this is I would be very grateful.
-
What is the difference between the definitions "int main (void)" and "int main (int argc, char *argv[])" and when to use which?
As per the current standard and cppreference these two are the correct way to define the
main()
function. I know what the parameters mean in either definition, and am not seeking clarifications on that aspect. What I'd like to understand is:- When to use
int main (void)
v/sint main (int argc, char *argv[])
. - Hypothetically, when the program doesn't expect command-line arguments, is there any difference to the compiler (let's say
gcc
andclang
) at all? - (Just for the sake of writing self-documenting code) should I use
int main (void)
when the program doesn't expect command line arguments andint main (int argc, char *argv[])
when it does?
- When to use
-
Increment a number without using arithmetic operators
All I want to do is increment the i++ at the end of the for loop without using arithmetic operators and I can only use bitwise operators. So no "+, ++, +=, -, --, -= ,∗, /, %". An exception is that I can use addition for pointer arithmetic like in the line
result += multiplicand;
Would I have to change it into a while loop or how would I do that?
int result = 0; int i = 0; for (i=0; i<multiplier; i++){ result += multiplicand; }
-
Is it possible to have an Android Studio project that also builds on Visual Studio 2019?
I looked a lot into it, and it appears there's no way to keep synced the
build.gradle
file from Android Studio andbuild.gradle.template
from Visual Studio, same thing forAndroidManifest.xml
andAndroidManifest.xml.template
andsettings.gradle
andsettings.gradle.template
andgradle-wrapper.properties
andgradle-wraper.properties.template
.Am I missing something or is there a way? It would be super cool to have both in a project since some people prefer VS and others prefer AS to work with Android projects.
Is there maybe a magic to keep autogenerating the
app.androidproj
file and the templates from the Android Studio originals? -
In Visual Studio, are there code comments for C++ like there are for C#?
In Visual Studio with C# you can hover over most of the default code and it will give you a pop-up description that tells you what the code is. I recently started learning C++ and am very much missing that helpful pop-up info. There's a pop-up, but it only contains the method signature, none of the other helpful descriptions that says what the thing is for.
All I could find were instructions on how to make my own, but I'm trying to find out if there are any default ones or maybe a tool I can add that will help.
Edit: Here are a couple pictures to explain what I mean. I don't want to make my own tool tips, I'm trying to find out if there's something that will help me understand what a function, field, etc is for while scrolling through them while in Visual Studio.
C# tool tip:
-
How would I access an Image file inside my soloution in C# WPF
I am trying to set the background of a programmatically created Canvas, Using the following method:
Canvas Object = new Canvas(); Object.Background = new ImageBrush(new BitmapImage(new Uri("pages/Asset/Untitled 6.png", UriKind.Relative)));
This URI WOULD WORK In XAML, for setting a background image however in C# the scope seems to be in a different folder.
-
Having problems getting bootstrap snippet to display as previewed
I tried using the following footer snippet below (in my base.html file, using Django), but am having problems getting it to display as previewed. I'm using bootstrap 5 for most of my code, but this snippet is supposed to be for bootstrap 4. Any guidance on where I'm going wrong would be greatly appreciated. TIA
Snippet Code for Footer:
<div class="footer"> <!-- footer --> <div class="container"> <div class="row "> <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 "> <div class="ft-logo"><img src="https://easetemplate.com/free-website-templates/cointrade/images/logo.png" alt=""></div> </div> </div> <hr class="footer-line"> <div class="row "> <!-- footer-about --> <div class="col-xl-3 col-lg-3 col-md-4 col-sm-6 col-6 "> <div class="footer-widget"> <div class="footer-title">Company</div> <ul class="list-unstyled"> <li><a href="#">About Us</a></li> <li><a href="#">Customer Support</a></li> <li><a href="#">Press</a></li> <li><a href="#">Legal & Privacy</a></li> </ul> </div> </div> <!-- /.footer-about --> <!-- footer-links --> <div class="col-xl-3 col-lg-3 col-md-4 col-sm-6 col-6 "> <div class="footer-widget"> <div class="footer-title">Quick Links</div> <ul class="list-unstyled"> <li><a href="#">News</a></li> <li><a href="#">Contact Us</a></li> <li><a href="#">FAQs</a></li> </ul> </div> </div> <!-- /.footer-links --> <!-- footer-links --> <div class="col-xl-3 col-lg-3 col-md-4 col-sm-6 col-6 "> <div class="footer-widget"> <div class="footer-title">Social</div> <ul class="list-unstyled"> <li><a href="#">Twitter</a></li> <li><a href="#">Google +</a></li> <li><a href="#">Linked In</a></li> <li><a href="#">Facebook</a></li> </ul> </div> </div> <!-- /.footer-links --> <!-- footer-links --> <div class="col-xl-3 col-lg-3 col-md-12 col-sm-6 col-6 "> <div class="footer-widget"> <h3 class="footer-title">Subscribe To Our Newsletter</h3> <form> <div class="newsletter-form"> <input class="form-control" placeholder="Enter Your Email address" type="text"> <button class="btn btn-default btn-sm" type="submit">Sign Up</button> </div> </form> </div> </div> <!-- /.footer-links --> <!-- tiny-footer --> </div> <div class="row "> <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 text-center "> <div class="tiny-footer"> <p>Copyright © All Rights Reserved 2020 | Template Design & Development by <a href="https://easetemplate.com/downloads/bitcoin-cryptocurrency-website-template-amazing-design " target="_blank" class="copyrightlink">EaseTemplate</a></p> </div> </div> <!-- /. tiny-footer --> </div> </div> </div> <!-- /.footer -->
I also used the following code in my HEAD tag:
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">
The code within the snippet is supposed to look like this:
This is what it actually looks like at the bottom of my web page:
-
Related products based on SKU similar part
In my Woocommerce website I am using this pattern for SKUs of related products: [first part shared]-[second part unique]; For example, 3 related products will have the following SKUs:
ABC100-260 ABC100-300a ABC100-b90a
I am looking for a way to display related products based on the shared part of SKUs (in the above example: "ABC100-") in each product display page.
Any help to find a plugin or code snippet would be appreciated very much.
-
Visual studio code snippet choices and variables
I am writing my own snippet to console.log
{ "Print to console": { "scope": "javascript,typescript", "prefix": "debug", "body": [ "console.log('${1|[Debug],[Server],[$TM_FILENAME]|}','${2:~Line: $TM_LINE_NUMBER ~ File:$TM_FILENAME}',${3:$TM_SELECTED_TEXT}); //debug", "$4" ], "description": "Log output to console" } }
Everything is ok except instead of file name static text TM_FILENAME is getting displayed in choices for placeholder '$1'
${1|[Debug],[Server],[$TM_FILENAME]|}
. How can I make filename to be displayed here? Thanks for suggestions