iostream.h (error C1083 )

Hi!

Btw. my first code.

I have this simple problem: the Visual C++ expresss -08 nags about this "iostream" and i cant figure out whats wrong.

Here's the piece of code:
1
2
3
4
#include "stdafx.h"
#include <string.h>
#include <iostream.h>
using namespace std;


it says "Cannot open include file: 'iostream.h': No such file or directory"

I have also tryed <iostream> (without .h) but it only gave me more errors.
Ewerything else seems to be OK

Last edited on
Dont put .h with the <iostream>.
And make sure your project type is CONSOLE :)
What errors you get when you use?#include <iostream>

Jeff
Last edited on
croconile:
I tryed allready, gives me just more errors (and project type is console =) )

Jeff HS:
here's the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Compiling...
stdafx.cpp
Compiling...
FirstCode.cpp
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(7) : error C2447: '{' : missing function header (old-style formal list?)
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(27) : error C2365: 'exit' : redefinition; previous definition was 'function'
        c:\program files\microsoft visual studio 9.0\vc\include\stdlib.h(371) : see declaration of 'exit'
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(27) : error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(int)' to 'int'
        There is no context in which this conversion is possible
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(27) : error C2447: '{' : missing function header (old-style formal list?)
Build log was saved at "file://c:\Documents and Settings\Compaq_Omistaja\Omat tiedostot\Visual Studio 2008\Projects\firstscript\lässi\Debug\BuildLog.htm"
FirstCode - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Do you have a semicolon after the brackets on main?

1
2
int main(); // the semicolon here will generate error code C2447.
{}


Also, they're right about the .h after iostream. Visual C++ Express 08 considers that an antiquated header. As for the rest of the errors, I can tell you what they mean, but I can't show you where the error is coming from without seeing your code. C2440 indicates that you've attempted an illegal type cast, and C2365 indicates that you've attempted to redifine a class member. If you want more specific information than that, post the code.

Hope this helps.
So the rest of the errors just have to be fixed? really good to know, thanks. I'll start solving them right away!

I first thought that the miss of iostream caused them =) thanks
Ok, i got the other problems solved, but there's just one thing: this error
error C2447: '{' : missing function header (old-style formal list?)
there are two of these errors
The only thing I know of that will cause that error is a loose '{' bracket is just floating around in your code somewhere. That's why a misplaced semi-colon can cause it. Post the offending code and I'll see if I can track down the cause.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//My first code
#include "stdafx.h"
#include <string.h>
#include <iostream>
#include "stdlib.h"
using namespace std;

{main () }
{
   int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
   ;cout<<"hello"<<endl;
   ;cout<<"How old are you"<<"?"<<endl;
   cin<<a;
   ;cout<<endl;
   ;cout<<a<<"?"<<" I'm" <<a<<" too!"<<endl;
   ;cout<<"whats your name"<<"?"<<endl;
   cin<<b;
   ;cout<<endl;
   ;cout<<"nice to meet you "<<b<<"my name is Johnny"<<endl;
           for (int g=10; n>0; n--) {cout<< g << ",";}
   ;cout<< "Download complete" <<endl;
   ;cout<< "Guess how many troijans are now in your computer" <<endl;
   cin<<c;
   ;cout<< "wrong" <<m<< "is more correct" <<endl;
   ;cout<< "have a nice day sucker"<<endl;
   ;cout<< "Type 0 to exit"<<endl;
   cin<<y;
   if (y == 0)
   {return 0;}
   else (y != 0)
   {return 0;}
};
main has to have a body.

You main is one block
 
{main()}


Also, main must return an int. You are returning something in your function yet you did not specify the return type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int main ()
{
   int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
   ;cout<<"hello"<<endl;
   ;cout<<"How old are you"<<"?"<<endl;
   cin<<a;
   ;cout<<endl;
   ;cout<<a<<"?"<<" I'm" <<a<<" too!"<<endl;
   ;cout<<"whats your name"<<"?"<<endl;
   cin<<b;
   ;cout<<endl;
   ;cout<<"nice to meet you "<<b<<"my name is Johnny"<<endl;
           for (int g=10; n>0; n--) {cout<< g << ",";}
   ;cout<< "Download complete" <<endl;
   ;cout<< "Guess how many troijans are now in your computer" <<endl;
   cin<<c;
   ;cout<< "wrong" <<m<< "is more correct" <<endl;
   ;cout<< "have a nice day sucker"<<endl;
   ;cout<< "Type 0 to exit"<<endl;
   cin<<y;
   if (y == 0)
   {return 0;}
   else (y != 0)
   {return 0;}
}


Insertion operator is the other way around, should be >> not <<
 
cin>>


Is your stdlib user defined? if not, then you need to use <cstdlib>. I suggest removing all the .h after the library names.
 
#include <string> 

the problem with the .h version is that the compiler may refer the string.h as c-style string library.

Also, you do not declare keywords and function names.
 
int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;


the variable m = c * 2; will cause garbage data to be multiplied by 2. You need to initialize c first before using the statement.

And a line does not start with a semicolon. A semicolon is used only at the end of a statement.

here is a fixed version. Make sure to understand what are your errors, it'll help you in the long run when programming in c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "stdafx.h"
#include <string>
#include <iostream>
#include <cstdlib> //I do not see where you used this library.
using namespace std;

int main(void) //void is optional, but I am always explicit.
{
   int a, b, c, y;
   cout<<"hello"<<endl;
   cout<<"How old are you"<<"?"<<endl;
   cin>>a;
   cout<<endl;
   cout<<a<<"?"<<" I'm" <<a<<" too!"<<endl;
   cout<<"whats your name"<<"?"<<endl;
   cin>>b;
   cout<<endl;
   cout<<"nice to meet you "<<b<<"my name is Johnny"<<endl;
           for (int g=10; n>0; n--) {cout<< g << ",";} //This line will execute fast. You need to use a timer to show a count down effect.
   cout<< "Download complete" <<endl;
   cout<< "Guess how many troijans are now in your computer" <<endl;
   cin>>c;
   cout<< "wrong" <<(c * 2)<< "is more correct" <<endl;
   cout<< "have a nice day sucker"<<endl;
   cout<< "Type 0 to exit"<<endl;
   cin>>y;
   if (y == 0) //regardless of what the user type, the function will still exit.
   {return 0;}
   else
   {return 0;}
}
Last edited on
Ok, ive done some work with the code, but now it error's 101 of these errors:
1
2
error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
        c:\program files\microsoft visual studio 9.0\vc\include\ostream(930) : see declaration of 'std::operator <<'


And the full script currently looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//My first code
#include "stdafx.h"
#include <string.h>
#include <iostream>
#include <cstdlib>
using namespace std;

int main () 
{
   int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
   std::cout <<"hello"<<endl;
   std::cout <<"How old are you"<<"?"<<endl;
   std::cin <<a;
   std::cout <<endl;
   std::cout <<a<<"?"<<" I'm" <<a<<" too!"<<endl;
   std::cout <<"whats your name"<<"?"<<endl;
   std::cin <<b;
   std::cout <<endl;
   std::cout <<"nice to meet you "<<b<<"my name is Johnny"<<endl;
           for (int g=10; n>0; n--) {cout<< g << ",";}
   std::cout << "Download complete" <<endl;
   std::cout << "Guess how many troijans are now in your computer" <<endl;
   std::cin <<c;
   std::cout << "wrong" <<m<< "is more correct" <<endl;
   std::cout << "have a nice day sucker"<<endl;
   std::cout << "Type 0 to exit"<<endl;
   std::cin <<y;
   if (y == 0)
   {return 0;}
   else (y != 0)
   {return 0;}
};
Last edited on
What is this line supposed to be?
 
int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;

It looks like you're trying to declare some integers, and then there's a lot of nonsense after c. Try this:
1
2
3
4
5
int a;
int b;
int c;
int m = c*2;
int y;


and when you use cin, the symbols point the other way:
 
std::cin >> y;


Your for loop declares g, but then it uses n. That's not right, try this:
 
for (int g=10; g>0; g--) {cout<< g << ",";}


That last else doesn't make much sense, try this:
1
2
else
{return 0;}

... Although it will return zero in either case, so you don't really need it at all.

You don't need a semicolon after the final curly bracket.

Put it all together:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//My first code
#include <string.h>
#include <iostream>
#include <cstdlib>
using namespace std;

int main () 
{
   int a;
   int b;
   int c;
   int m = c*2;
   int y;
   std::cout <<"hello"<<endl;
   std::cout <<"How old are you"<<"?"<<endl;
   std::cin >>a;
   std::cout <<endl;
   std::cout <<a<<"?"<<" I'm" <<a<<" too!"<<endl;
   std::cout <<"whats your name"<<"?"<<endl;
   std::cin >>b;
   std::cout <<endl;
   std::cout <<"nice to meet you "<<b<<"my name is Johnny"<<endl;
           for (int g=10; g>0; g--) {cout<< g << ",";}
   std::cout << "Download complete" <<endl;
   std::cout << "Guess how many troijans are now in your computer" <<endl;
   std::cin >>c;
   std::cout << "wrong" <<m<< "is more correct" <<endl;
   std::cout << "have a nice day sucker"<<endl;
   std::cout << "Type 0 to exit"<<endl;
   std::cin >>y;
}

There's a bunch of typos, and some of the cins don't work, but I'll leave those problems as an exercise to the reader :)
Last edited on
Sorry I took a while in getting back to you. It looks like vince1027 gave you quite a bit of help though. Here's some more:

First of all, since you have the statement 'using namespace std;' at the top of your program, you don't need all the 'std::' before the cin or cout.

In the int declarations, get rid of the 'cout, cin, endl, if, else, for, main, exit;
I'm not really sure what it is you're trying to do, but those aren't valid integer declarations. Also, as vince1027 pointed out to you before, m=c*2 will produce garbage since you haven't initialized int c to any value.

As vince1027 pointed out, the insertion operator following each cin statement should be >>, not <<.

Where you ask for a name, you're attempting to store the name into an int. You won't get the intended results that way. Declare b as a string instead and use that to store the name.

At the end of the program, where you have the if else statement: When you use an else statement the compiler is not expecting another conditional test unless you tell it to. Hence your else, should be 'else if'. Note that this still doesn't do anything, since you have the same results either way.

By the way, interesting choice for a first program. I hope the trojans are a joke, and not something you plan to do with any programming skills you learn...

In the for loop, you've declared int g, and then use n for the rest. It's going to wonder what n is, since you haven't declared it.

[Edit] It looks like I've reiterated a lot of what magicalblender posted while I was typing my response.
Last edited on
You are still doing operations with uninitialized variables.
1
2
3
4
5
   int a;
   int b;
   int c;
   int m = c*2;
   int y;


It's always a good idea to initialize all your variables. 0 is a good value even to pointers.
1
2
3
4
5
   int a = 0;
   int b = 0;
   int c = 0; // you might wanna change the value of c. unless you want m = 0*2;
   int m = c*2;
   int y = 0;


you dont really need m though if all you want is this
 
std::cout << "wrong" <<m<< "is more correct" <<endl;

 
std::cout << "wrong" << c * 2<< "is more correct" <<endl;

gives better results in the current state of your code.

Jeff
Last edited on
Actually, after reading through my post, I have to apologize that I made a mistake.

The insertion operator is indeed << because we are inserting to the object stream. The extraction operator is >>.

Still, the one you use for standard input is operator "double bigger than" - my friend like to call it that.

I did not notice this until gzero's reply.
Thank you all, this should help me fix all problems.

And btw im not gaing to use programming skills for spreading virus; it's just a joke =)
Topic archived. No new replies allowed.