C/C++ [C++] error: File cannot be found

  • Thread starter Thread starter happysauce
  • Start date Start date
  • Tags Tags
    Error File
AI Thread Summary
The discussion revolves around a user learning C++ with Visual Studio 2010 and encountering issues while compiling programs. Initially, the user successfully created a simple "Hello World" program but faced an error when trying to run a second program that involved variables. The error indicated that the executable file could not be found. This was identified as a potential issue stemming from having two main() functions across different source files within the same project, which leads to linking errors. To resolve this, the user created separate projects for each program. The conversation also clarified that while a project must contain one main() function as the entry point, it is permissible to define multiple other functions within the same project, regardless of their names.
happysauce
Messages
42
Reaction score
0
So I just started teaching myself C++ using visual studio 2010. I started with a nice easy program.

First thing I did was created a new project called "Tutorial." Under source files I right clicked and selected add -> new item, I named it Introduction.cpp. I created this:

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World";
cout << endl;
cout << "My name is Neil";

system("pause");
return 0;
}



Worked out fine. It compiled and ran properly.

So I added another item and named it variables.cpp and made this:

#include <iostream>
using namespace std;

int main ()
{
int a, b, c;
int sum;


a=1;
b=2;
c=3;
a=a+4;
sum = a+b+c;


cout << sum;
system("pause");
return 0;

}

This time when I compile and run I get an error Unable to start program "Tutorials/Debug/Tutorial.exe the system in the file cannot be found.

So I go back and try the other program and i get the same error. A lot of people online say to check the Debug file and look for it, but I didn't find any. I did find tutorial.exe.imbed.manifest though. I don't really know what's going on or how to fix this.
 
Technology news on Phys.org


Are you building a project with two main() functions? That should result in a linking error.
 


Ah that makes sense. I actually fixed it by just making another project with variables instead. So now I have a projected name introduction and a project named variables. My question now is, can I have two different codes in a project using no main function, like name one of them function_one () and the other function_two () (or even main)?
 


happysauce said:
My question now is, can I have two different codes in a project using no main function, like name one of them function_one () and the other function_two () (or even main)?

Your source must contain one main() function. This is the program's entry point. What you name other functions in the same source file or in different source files in the same project is up to you.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top