Alright, I am having a problem with an error message that comes up, i am pretty sure the code is alright, but it might be the code, i have tried re-installing VB (Visual Basic 2010). i have tried a few things on the web and nothing. here is the error im getting...

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>K:\C++ Programming\20pg372\Debug\20pg372.exe : fatal error LNK1120: 1 unresolved externals

I just don't get it... Here is my code im trying to count the empty space in between each word in the file the user inputs...

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main ()
{
	int size = 0, count = 0;
	char ch;
	int Option1; 
	string FILE;
cout <<"Hello, this program will count the number of words in a file of your choice!"<<endl;
cout <<"If you are ready to begin enter 1 and press enter, Press 2 and enter to exit"<<endl;
cin >> Option1;
if (Option1 == 2)
	{
	cout<<"Have a nice day"<<endl;
	return 0;
	}
if(Option1 == 1)
{
	cout <<"Alrighty please enter the name of the file you wish to open"<<endl;
	cout <<"Also include the file format! for example( .txt, .doc, .rtf ect.)"<<endl;
	cin >> FILE;

    ifstream in_stream;
	in_stream.open(FILE);
		
	if(in_stream.fail())
		{
			cout << "input file failed to open."<<endl;
			exit(1);
		}
	in_stream >> ch;
	while(in_stream >> ch)
	{	
		if(isspace(ch)) 
		{
			count++;
			in_stream >> ch;
		}
	}
cout<<count;
system("pause");
in_stream.close();
}
}

Recommended Answers

All 5 Replies

I am assuming you meant Visual C++, not Visual Basic. Otherwise, you've gotten very confused about the language you are using :?:

The error indicates that the function _tmain() is missing. Now, in UNICODE enabled Windows programs, _tmain() is the equivalent of the main() function in regular C++. That you are getting this now, but not before, seems to me to imply that you'd changed the settings in the project to compile the program for UNICODE, whether you were aware of doing so or not. At least, that's my impression fit it; others may know more about this than I do.

A search on this matter comes up with this advice:

Please change the "subsystem" in your linker settings from "Windows" to "Console".

Whether this will do the trick or not, I am not sure. An alternative solution proposed by R. Stilskin is to

Create a new project following these steps:

When you start the new project wizard, click Win32 Console Application, enter a project name, click OK, then on the next screen click "Application Settings", then "Console application" and "Empty project".

That gives you a completely empty project, so click on Project/Add New Item/C++ File, enter a filename for your main file, and that will open an empty .cpp file.

I am pretty certain that the latter should work even if the former does not.

I had this problem earlier and I read online that it could be caused by missing definitions. I believe you may have to add the library.

yes, Schoil-R-LEA I did not mean visual basics i ment visual c++, i thought that it might of been a library missing as well i have changed the sub system and nothing. im wondering if i just re-write the code in an other project, instead of copy and past it to a new one might solve it. I will re post back, thx for responding. for I had no answers to this problem need a few other suggestions or ideas from people. PLZ keep posting ideas till its FIXED. Thanks!

You probably started the project as a WinForms app, but changed the internals to be a console app.
I suggest starting over with the right project type. You can copy/paste this existing code into the new project.

I have tried copy and pasting it into a new project and nothing. I re-typed out the whole the project into a new project and i have gotten it to work thx for the help guys. If i hvae any problem with my code i will juts post another form.

thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.