visual studio c++ cannot open any source file [duplicate] - c++

This question already has answers here:
Cannot open include file: 'ctype.h': No such file or directory
(4 answers)
Visual Studio 2022: Cannot open include file: 'ctype.h'
(1 answer)
Closed 7 months ago.
I've been using visual studio for my unreal projects for some time now.
But when i try to code something in vs i get the error "cannot open source file".
I have a very basic c++ code;
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
when i debug this code i get the error that almost every header file(435 header files) like float.h, string.h, time.h etc. cannot open.
When i try compiling the code using gcc i get another error but when i use g++ i get no error.
So i'm assuming i need to change debug options of visual studio. I've tried buy i couldn't figure that out.
How can i make visual studio run the code properly?

Related

Errors in C++ Hello World program

Installed c++ in visual studio 2019 some time ago and it worked perfectly. Today when I launched I got 490 errors. This is a screenshot of what a Hello World looks like: https://imgur.com/yxIs9Np
I am completely new to c++ so I dont know whats wrong, I have tried to search for the error but I could not find anything. I have tried to reinstall c++ in vs and updated vs to the newest version.
code:
#include <iostream>
int main() {
std::cout << "Hello World!\n";
}
its nothing wrong with the code, I think something is wrong with the librarys. For some reason I get 17 errors " cannot open file "[Some name].h" "
Reinstalled visual studio, this worked. The problem was that it dident include C:\Program Files (x86)\Windows Kits\10

What are the standard include paths for MS Visual C++?

I am trying to build a hello-world C++ application using Microsoft Visual C++.
#include <iostream>
int main() {
std::cout << "Hello, world. " << std::endl;
return 0;
}
I get this error:
main.cpp(1): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
What are the standard include paths for Microsoft Visual C++?
Note: I am building from the command-line, not from Visual Studio
I actually just read through all of the documentation on this at: https://msdn.microsoft.com/en-us/library/ms235639.aspx
The material looks detailed and complete. If you get things configured like they require then it must work. They provide plenty of checks and conditions for ensuring that you are set up properly.
I am seriously suspecting that you aren't using a developer command prompt window.
I just did it myself and it works. Use Notepad and name the files like they tell you to do.
"Hello world!!"

Visual Studio Compiler Error

I was making a simple DLL as a test in visual studio 2010.
Here is the code for SimpleCPP.cpp
#include iostream
#include "SimpleH.h"
namespace nmspace
{
void myclass::Crap()
{
std::cout << "Test." << std::endl;
}
}
Here is the code for the header file
#include <iostream>
namespace nmspace
{
class myclass
{
public:
static __declspec(dllexport) void Crap();
};
}
My problem is when I compile I get an error that says that visual studio can't find the file SimpleDLLd.dll. In closer inspection I see that when the program is compiling visual studio adds a d to the release files. For example when the DLL is supposed to be SimpleDLL.dll (The project name is SimpleDLL) visual studio adds a d and outputs SimpleDlld.dll. I tried doing the same thing in another project and it did the same thing. I then proceeded to Visual Studio 2013 and copy and pasted the contents of the cpp and header files into new files and surprisingly got the same exact result as Visual Studio 2010. How would I fix this error? Thank you for responding.
Check the name of the build target in your project file settings. The name of the resulting file should be in the
Linker->General->Output File
setting in the project which is usually $(OutDir)$(TargetName)$(TargetExt) by default.

Can't run simple Visual Studio 2013 project

I was trying to install OpenCV 2411 in Visual Studio 2013, but i receive an error when I try to build the project. The error says: LINK1104: cant open file opencv_core2411.obj
I then decided to check that if I created a simple C++ example without the OpenCV 2411 library and see if i will receive an output. I created a new project to print only the word 'hello', but upon building the project I received the same error message mentioned before: LINK1104: cant open file opencv_core2411.obj despite for that new project that should display 'Hello'; I have not imported the Opencv 2411 libraries.
Why am I receiving that error while the project is never relevant to OpenCV 2411 library?
Try the following steps:
Close and reopen Visual Studio.
Select File -> New Project -> Visual C++ -> Empty Project
Right click source files and select -> Add -> New Item...
Select C++ File (.cpp) and give it a name, i.e. main.cpp
Paste in the "Hello" code (at the bottom of answer)
Press F5 to Start Debugging
Hello Code:
#include <iostream>
int main(){ std::cout << "Hello" << std::endl; return 0; }

Building a C++ project in Visual Studio doesn't create any files

I recently decided to start learning Visual Studio so that it replaces my need for CodeBlocks and MinGW for C++ programming.
So, today I made a new Win32 C++ Console Application, wrote down this code in a new .cpp file
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a << endl;
return 0;
}
and compiled it. The log said
1>------ Build started: Project: CPP_CONSOLE_TEST, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(357,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
and I though my code was compiled and my .exe was created.
Then, upon trying to debug my program, Visual Studio said:
Unable to start program 'C:\Users\XYZ\Documents\Visual Studio 2013\Projects\CPP_CONSOLE_TEST\Debug\CPP_CONSOLE_TEST.exe'. The system cannot find the file specified.
I then opened the Debug folder of the project and it was completely empty...
I've been searching around Google for some time and I even tried to "Repair" my Visual Studio build with no results. Any help?
Quick edit: Just tried compiling a C# app, just to see if the IDE itself was the problem. It compiled and ran just fine, so it's some issue with the Visual C++ compiler and its settings...
Turns out I hadn't added the source file to the Project... :|
Visual Studio, has its own vision of c++ projects. By default, it needs a #include "stdafx.h" on top of your cpp file, with the associated stdafx.h and stdafx.cpp files.
Then, in a c++ visual studio project, the real definition of the main function is int _tmain(int argc, _TCHAR* argv[]). But it should work with your definition.
Why don't you try to use Serge Rogatch's solution?
There is a bug in Visual Studio which leads to problems when project has long path.