How do I set up Visual Studio with default headers and comments? - c++

I am fairly new to using Visual Studio. Currently I am using Visual Studio 2015 version. Currently when I set up a new C++ console application project (with Precompiled header off or on) it displays the following:
// Name of project.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main()
{
return 0;
}
Every time I create a new project I have to waste my time entering in my header information and comments. I would like it to look like this every time I create a new C++ console application project.
// *********************************************************************
// Name:
// Description:
// Date:
// Class Section:
// Title:
// *********************************************************************
//Heading information
#include <iostream>
#include "stdlib.h"
#include "stdafx.h"
using namespace std;
//Main function
int main()
{
//Pause system and end main function
system("pause");
return 0;
}
Is it possible to set up Visual Studio 2015 to display the code above every time I create a new project? Thanks

Create a new console application.
Edit the file to be as you want it in the new one.
Select "Export Template..." in the "File" menu.
Walk through the wizard (choose a name for your new template, etc.)
Be sure the "Automatically import the template into Visual Studio" is checked.
Restart VS
Select "New Project"
Select "Visual C++" in the tree control on the left
Select your new template in the list in the middle
The usual new-project stuff (name and location for the project, etc.)
[Note: As I'm writing this, I'm looking at it in VS 2013. I don't recall it's changing in VS 2015, but it's possible.]

Related

Disabling Auto-generated comments in Visual Studio Enterprise 2017

I would like to disable auto generated comments of Visual Studio every time I create new project. Sample template of visual studio can be seen below. I don't want any of these comments. Thanks for any help.
`
// ex6_page174.cpp : This file contains the 'main' function. Program
execution begins and ends there.
//
#include "pch.h"
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project >
Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open >
Project and select the .sln file
`
You can't.
For better or for worse, this is by design.

Default code in each new cpp files in Visual Studio 2015

I am currently studying C++ using Visual Studio and I don't want to use a new project for each and every small topic that I go through, instead, I have one project into which I Add and Remove Cpp files as needed.
I wonder if there is a possibility to set a default piece of code into each newly added Cpp file so that I don´t need to copy it every time. Some simple code like this
#include <iostream>
using namespace std;
int main()
{
cin.get()
return 0;
}

Visual studio runs c++ in a white window rather than console

I want it to run just in the cmd but all I get is this white window. Any help?
Code:
//
// pch.cpp
// Include the standard header and generate the precompiled header.
//
#include "pch.h"
#include <iostream>
using namespace std;
int main() {
cout << "test";
return 0;
}
Visual Studio provides different kinds of project you can start with.
You are looking for "Win32 Console Application" which already provides the standard configuration that employs a console.
You can also use an empty C++ project, but then you must find all the required settings that enable the console environment.

C++ Visual Studio 2010 "Unable to start Program"

I've been looking arund and i can't find the problem for this. Whenever i try to debug my project, i get this error
Unable to start program 'C:/Users/.../project/.dll'
All i did was create a new application than put this
// This is the main DLL file.
#include "stdafx.h"
#include "asddsa.h"
/*
* File: main.cpp
* Author: Arhowk
*
* Created on March 22, 2013, 10:15 PM
*/
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
using namespace std;
void main()
{
cout << "Hello World!" << endl;
cout << "Welcome to C++ Programming" << endl;
}
any help? I can provide more debug info if needed, but cant find any. Running VS2010 Express on a W7 x64 machine
You shoud create an exe project like "Win32 Console Application"
"C:/Users/.../project/.dll" looks wrong, Right click your project, select "Properties", check "General->TargetName", "Debugging->Command" and "Linker->General->Output File"
When you created your project, what type did you create? It looks like you created a DLL project. DLLs can't be ran directly, you need to have an exe that will load one or more DLLs.
If you create an exe project, you should be able to run it directly to test your code.

Visual C++ can't open include file 'iostream'

I am new to C++. I just started! I tried a code on Visual C++ 2010 Express version, but I got the following code error message.
------ Build started: Project: abc, Configuration: Debug Win32 ------
ugo.cpp
c:\users\castle\documents\visual studio 2010\projects\abc\abc\ugo.cpp(3): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is the code:
// first.cpp -- displays a message
#include <iostream> // A PREPROCESSOR directive
int main(void) // Function header
{ // Start of a function body
using namespace std;
cout << "Come up and C++ me sometime.\n"; // Message
// Start a new line
cout << "Here is the total: 1000.00\n";
cout << "Here we go!\n";
return 0;
}
Replace
#include <iostream.h>
with
using namespace std;
#include <iostream>
Some things that you should check:
Check the include folder in your version of Visual Studio (in "C:\Program Files\Microsoft Visual Studio xx.x\VC\include", check for the file which you are including, iostream, make sure it's there).
Check your projects Include Directories in <Project Name> → Properties → Configuration Properties → VC++ Directories → Include Directories (it should look like this: $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;)
Make sure that you selected the correct project for this code
(menu File → New → Project → Visual C++ → Win32 Console Application)
Make sure that you don't have <iostream.h> anywhere in your code files, Visual Studio doesn't support that (in the same project, check your other code files, .cpp and .h files for <iostream.h> and remove it).
Make sure that you don't have more than one main() function in your project code files (*in the same project, check your other code files, .cpp and .h files for the* main()` function and remove it or replace it with another name).
Some things you could try building with:
Exclude using namespace std; from your main() function and put it after the include directive.
Use std::cout without using namespace std;.
I had this exact same problem in Visual Studio 2015. It looks like as of Visual Studio 2010 and later you need to include #include "stdafx.h" in all your projects.
#include "stdafx.h"
#include <iostream>
using namespace std;
The above worked for me. The below did not:
#include <iostream>
using namespace std;
This also failed:
#include <iostream>
using namespace std;
#include "stdafx.h"
You are more than likely missing $(IncludePath) within Properties → VC++ Directories → Include Directories.
Adding this should make iostream and others visible again. You probably deleted it by mistake while setting up your program.
If your include directories are referenced correctly in the VC++ project property sheet → Configuration Properties → VC++ directories → Include directories, the path is referenced in the macro $(VC_IncludePath).
In my Visual Studio 2015 this evaluates to:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
using namespace std;
#include <iostream>
That did it for me.
It is possible that your compiler and the resources installed around it were somehow incomplete. I recommend re-installing your compiler: it should work after that.
I got this error when I created an 'Empty' console application in Visual Studio 2015. I recreated the application, leaving the 'Empty' box unchecked. It added all of the necessary libraries.
Make sure you have Desktop Development with C++ installed.
I was experiencing the same problem, because I only had Universal Windows Platform Development installed.
Microsoft Visual Studio is funny. When you're using the installer, you must checkbox a lot of options to bypass the .NET framework (somewhat) to make more C++ instead of C# applications, such as the CLR options under desktop development... in the Visual Studio installer.... the difference is the C++ Win32 console project or a C++ CLR console project.
So what’s the difference? Well, I'm not going to list all of the files CLR includes, but since most good C++ kernels are in Linux... So CLR allows you to bypass a lot of the Windows .NET framework because Visual Studio was really meant for you to make applications in C#.
Here’s a C++ Win32 console project!
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!" << endl;
return 0;
}
Now here’s a C++ CLR console project!
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine("Hello, World!");
return 0;
}
Both programs do the same thing .... the CLR just looks more frameworked class overloading methodology, so Microsoft can great its own vast library you should familiarize yourself with if so inclined.
Keywords (C++)
Other things you'll learn from debugging to add for error avoidance:
#ifdef _MRC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
If you created an environment variable with the name IncludePath, try renaming it to something else.
This name will override $(IncludePath) inside project properties.
Quick fix for small programs:
Add: #include <cstdlib>
In my case, my Visual Studio 2015 installed without selecting C++ package, and Visual Studio 2017 is installed with the C++ package. If I use Visual Studio 2015, opening a C++ project will show this error, and using Visual Studio 2017 will be no error.
I had this problem too. I used this code (before main();) in Visual Studio 2022, and it turned OK:
#include "pch.h"
#include <iostream>
using namespace std;
using namespace winrt;
using namespace Windows::Foundation;
In my case, the error occurred when I created a file in VS Code, without giving the .cpp extension. It resolved when I renamed it with the .cpp.
// first.cpp -- displays a message
#include <iostream> // a PREPROCESSOR directive
using namesapce std;
int main() // function header
{ // start of a function body
///using namespace std;
cout << "Come up and C++ me sometime.\n"; // message
// start a new line
cout << "Here is the total: 1000.00\n";
cout << "Here we go!\n";
return 0;
}