Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Visual C++ Fatal Error??


  • Please log in to reply
7 replies to this topic

#1 Fasih

Fasih

  • Members
  • 36 posts
  • OFFLINE
  •  
  • Local time:03:42 AM

Posted 12 March 2010 - 09:49 PM

Ok this is starting to get on my nerves. I have been trying to do some programs for school, I have to do about 20 different in 1 week and for some reason Visual C++ somehow cant seem to find "iostream" or "iostream.h"

It was working fine, but just recently it started giving me this fatal error. I cant compile any program. I had Visual C++ 2008. I re-installed it, nothing happened. I uninstalled it, and downloaded the 2010 beta, and still nothing. I don't know why, but it just cant find iostream.

Can anyone help? Much appreciated. Thanks

-Fasih

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:42 AM

Posted 12 March 2010 - 11:16 PM

Can you post example code and/or the exact error message produced by the compiler? It's difficult to diagnose what's going on from the anecdotal storytelling :thumbsup:

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Fasih

Fasih
  • Topic Starter

  • Members
  • 36 posts
  • OFFLINE
  •  
  • Local time:03:42 AM

Posted 14 March 2010 - 12:49 PM

Yeah sure, here's a bit of code:

#include "stdafx.h"
#include "iostream.h"
#include "stdlib.h"
#include "conio.h"
#include "string.h"

main() {

	int num1, num2,count=0,y;
	float avg;
	cout << "Average Maker";
	cin >> num1;
	cin >> num2;
	while (count <=3)
	{
	for (int x = 1; x<=12;x++)
	{
		printf (".");
		y++;
		if (y == 3)
			clrscr;
			
	}	count++;
	}
		avg = (float)(num1+num2)/2;
	cout << avg;
	//return 0;
}

and here's the error message:
Posted Image

Edited by Fasih, 14 March 2010 - 12:53 PM.


#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:42 AM

Posted 14 March 2010 - 02:14 PM

That's because the program is not valid ANSI C++. When you ask for a standard header, it must be in angle brackets <>, not quotes "". Quotes tell the compiler that the header asked for is part of your project and should be literally looked for, while angle brackets tell the compiler to search for the correct header.

For the same reason, the compiler won't be able to find
#include "stdlib.h"
or
#include "string.h"
but the complier stops looking for headers once the first failure is found. You should probably be using the C++ headers anyway, <cstdlib> and <cstring>, if you're making a C++ project.

Also, iostream.h is not a standard header and never has been in a final standard. <iostream> is the correct header file and the one you should be using.

"conio.h" is also a nonstandard header which was included on some forms of Borland's C++ Builder, and is not part of ANSI C++ in any description. The functions you're using from conio, namely clrscr, do not exist with the version of conio.h shipped with Visual Studio. You need to use Visual Studio's functions: http://msdn.microsoft.com/en-us/library/7x2hy4cx(VS.71).aspx. Unfortunately, there is no equivalent of clrscr() in visual studio's version of conio.

You are calling printf(), but have not included <cstdlib> or <stdlib.h>.

int num1, num2,count=0,y;

is not valid because you are not allowed to initialize variables in a multivariable declaration. count must be initialized elsewhere or declared by itself.

Your declaration of main() is invalid, main must return an int. C++ drops the "default-to-int rule" of C.

You have not specified the correct namespace for the standard streams cin, cout, and the like.

Simply put, the program is not valid, and the compiler is correct to reject it. This should compile:
#include <iostream>
#include <cstring>
#include <cstdlib>

int main() {

	int num1, num2, y;
	float avg;
	std::cout << "Average Maker";
	std::cin >> num1;
	std::cin >> num2;
	for(int count = 0; count <=3; count++)
	{
		for (int x = 1; x<=12;x++)
		{
			std::cout << ".";
			y++;
			if (y == 3)
				std::system("cls");
		}
	}
		avg = ((float)(num1+num2))/2;
	std::cout << avg;
	return 0;
}

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 Fasih

Fasih
  • Topic Starter

  • Members
  • 36 posts
  • OFFLINE
  •  
  • Local time:03:42 AM

Posted 14 March 2010 - 04:04 PM

Oh well i just started learning C++ in school, and we're using an old version of borland.

Also, now its telling me:

Add directive to 'StdAfx.h' or rebuild precompiled header



#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:42 AM

Posted 14 March 2010 - 04:41 PM

Ahh -- add #include "stdafx.h" to the top of that. You can also turn off Precompiled Headers in the options for your project.
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#7 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:05:42 AM

Posted 16 March 2010 - 08:59 AM

int num1, num2,count=0,y;

is not valid because you are not allowed to initialize variables in a multivariable declaration. count must be initialized elsewhere or declared by itself.


I always thought you can assign values at the time of declaration, in any random way, only all the variables should be of same type. My good old ANSI C++ by Jesse Liberty book says so. I do not know if standards have changed now.

#8 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:42 AM

Posted 16 March 2010 - 10:02 AM

Romeo29:
Yes, my mistake. My C++ book has this kind of stuff in the "C" section -- perhaps it was changed in ANSI C++? Visual Studio is accepting
int somefunc()
{
	int a = 0, b, c;
}
which to my understanding was not legal. Oopsl.

Have a nice day,
Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users