Visual Studio 2012 C++ Empty Project error? - c++

I keep attempting to make a new C++ Empty Project Console App but when I make the project the VS (2012) screen literally is empty. No place to write my code, how do I fix?

That is what a empty project is. If you want a file (place to write code) you have to right click on a folder and add a source file. I suggest calling it main.cpp. You must also have a main function inside of it.
int main()
{
return 1;
}
As a beginner I dont suggest you start empty projects.
You probably want to create a console application. That will give you a place to write your code.

Don't create an empty project.
Create "Win32 Console Application". It will create main file method into which you can insert your code

Related

My Visual Studio can't find files and so can't do basic operations. What's wrong with it?

Using C++, if I launch an 'empty project', create a new C++ file, and try to run it, I just get this error message:
Unable to run program 'C:\Users\User\source\repos\Project2\Debug\Project2.exe' The system cannot find the file specified
I go to the file it's referencing and the file IS there -- what??
Using a 'Console App' project is different: it will actually compile and run the code.
Similarly, I can't join new header files to the main file, not even in a 'Console App' project: if I write the code for doing #include "Header.h", I get a red line underneath #include, and if I hover over that it says:
cannot open source file "Header.h"
I'm new to coding, and don't know why I'm having such a seemingly absurd problem here. Help!
You should create a new project and then create a c++ file. While adding a file, make sure to select c++ console application and do not check empty project if you are new.
From the result you described, I suspect you used File -> New file to add that cpp file, right? This does NOT add that file to a project.
Instead, you should right-click the Project file in the Solution explorer, select Add new item (or Project -> Add new item menu), and choose the C++ file type.
This works!

Source file header file and other files are not displayed when I create empty C++ Project in visual studio 2019

I am very new to visual studio and I watched a couple of tutorials to understand how to use it, But I ran into a problem. Every person I watched on YT has a source file, header file, and other files when creating an empty Project but this isn't a case for me and I basically can't write anything.
when I try to add a CPP file it doesn't even show an option to add it, it only shows class and resource when I right click and press on add. Basically, I want the files to show so I can create my main program and play around with it.
Help is much appreciated.
First Create an empty project .
Second Go to solution explorer.
Third Right click the source file option.
Fourth Go to add and create a new item
Fifth Select .cpp file and press add.
And Congrats your .cpp file is created. Do the same procedure to create header file and class.

Visual Studio - C++ New File Default Code

Hey everyone I have a comfort problem is Visual Studio 2017 (I use 2017 because of school requirement).
Always when I start a new C++ Project or C++ File I get the default code:
// ConsoleApplication4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#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
It's very annoying for me to delete it every time and I'll be happy to know how to remove the default code. I searched the Internet and Microsoft MSDN and I didn't find any solution. Thank you for your help, this website helps me a lot!
There are two methods to create a empty project.
1.1 Create a project.
1.2 Edit the project until it is ready to be exported as a template. For example, you might want to edit code files to indicate where parameter replacement should take place. See How to: Substitute parameters in a template.
1.3 On the Project menu, choose Export Template.
The Export Template Wizard opens.
1.4 On the Choose Template Type page, select Project Template. Select the project you want to export to a template, and then choose Next.
1.5 On the Select Template Options page, enter a name and optional description, icon, and preview image for your template. These items will appear in the dialog box where you create a new project. Choose Finish.
You could use Windows Desktop Wizard.
Then select Empty Project.

compile single c++ source file in 1 project in visual studio

i know a lot of people asked this question, but i can't find how to do it. Is there
a way to build only one source file in visual studio 2017? without new project, i'm learning c++, so i can't make huge thing now, just focus to code(now i'm learn data structure and algorithm),most of my exercise is about <200 code lines, so it great to compile new file without whole project, sometimes i need a few lines of code to test my algorithm,please help me, thanks all you guy, because v.s is very good ide so i want to stick with it.
If you just have one file and want to build it without waiting 1-2 minutes for the IDE to pop up,
Find the Developer Command Prompt in your list of applications - it is under the Visual Studio directory in the Application menu.
cd /d to your directory. cd will take you here if you are on the same drive as visual studio. If you are on a different drive, use cd /d.
Use your favourite editor (notepad, vim, geany, notepad++, nano, microemacs etc) to create the file.
cl sourcefile
Run the excutable.
Unlike what visual studio does, you executable will now be in the same directory as your source. Editors like geany have a build button (the brick icon). All you need to do is fill in how to build: in this case, the cl command.
If you want a one file project, just follow these steps.
Create New Project - File -> New -> Project
Fill in filename, select Win32 Console Application. Note the directory - if it is not where you want it, change it. Click OK
Application Wizard pops up, click Next
Application settings - select Empty project, click Finish
Open Solution Explorer. Right click Source Files. Menu pops up, select Add -> New Item
Add new item dialog pops up, fill in your filename.
If you don't know how to create a new project and a new solution, it will be good to learn those basic concepts and use them to write, test, and debug your code.
You can use one Visual Studio project to do all the learning.
Let's say you want to test "algorithm 1". Then,
Create a header file for it and a source file for it -- call them "test-algorithm-1.hpp" and "test-algorithm-1.cpp".
Add them to the project.
#include the header file in the main .cpp file of the project.
Call the function to test "algorithm 1" from main.
#include "test-algorithm-1.hpp"
int main()
{
test_algorithm_1();
}
When you are ready for testing "algorithm 2", repeat the above steps. The main .cpp file can now be.
#include "test-algorithm-1.hpp"
#include "test-algorithm-2.hpp"
int main()
{
test_algorithm_1();
test_algorithm_2();
}
If you want to avoid testing "algorithm 1" while testing "algorithm 2", simply comment out the corresponding line in main.
int main()
{
// test_algorithm_1();
test_algorithm_2();
}
On the source file you don't want to be included in the project, simply right click, select Properties. There you will find in General a field 'Excluded From Build'. Type true/yes there and the source file will be deactivated.

Changing the main file in a C++ netbeans project

When I create a new C++ project in netbeans,it prompts me to choose a name for the main file of the project
this is the file that gets executed when I press "Run" in the IDE
does anybody know how to change this file to another one AFTER I've already created the project?
You don't need to change the name or point to a different file.
In C++, on NetBeans or any other IDE, just place main function on a different file (the file you want to RUN when you press RUN on the IDE) and you should be done.
When we first time build and run a c project in netbeans- if there are more than one file with main() then it prompts us to select one of those files to be run. But after that it doesn't ask us to select a main file rather it uses the same file selected earlier, every time we run the program. So how to select other main file once we have selected one file during first attempt to run. I believe this is your question.
Answer: Right click project => select Properties => select make option under Build (in categories) =>Against Build result specify your file that you want to run. You can easily browse files with main() there. See picture-