Hi all,

I have a simple program:

#include<iostream>
using namespace std;
6
int main()
{
    char x;
    do
    {
        scanf("%c", x);
    } while (x != 'y');
    return 0;
}

and for some reason when i gcc test.c i get
"test.c:1:20: fatal error: iostream: No such fiel or directory
compilation terminated."

I had a look around but couldn't find oput what the problem is.

This is the first time I have used gcc to compile since i installed so could the iostream fiel be missing :S?

Please help.
Thanks

I don't think there is any use of iostream in this program as you're using scanf() not cin

for scanf() the header is stdio.h

This is the first time I have used gcc to compile since i installed so could the iostream fiel be missing :S?

try using iostream.h
may be your compiler is old and doesn't support only iostream. If still you face the same error, then the file may be missing

Actually, the problem is that iostream is a c++ header file. Also namespaces are a c++ thing.
If you are using GCC for C, then you need to #include <stdio.h> for scanf.

If you are trying to compile C++, you need to use g++ not GCC.
You might also want to consider using cin (which is provided by iostream) rather than scanf, which is an old C function which is superceded by C++'s i/o streams implementation.

commented: Good +5

Incidentally, if you must use scanf (which you really shouldn't in c++) you can #include <cstdio>

Jason, Since this is the C forum, why all the C++ suggestions? Steer him correctly to C solutions.

commented: Pointless post. +0

Walt, I am aware of which forum this is, but from the OP's post it's kinda ambiguous which language they are trying to write in. Are they trying to write in C or C++? They have an extremely bad mix of both in their code.

And it wouldn't be the first time that a noob incorrectly posted a C++ question in the C forum would it? How many times has C code been incorrectly posted in the C++ forum, or vice versa?

Because of the ambiguity, I simply tried to cover both bases. Does that really deserve being downvoted?

If the OP's code was intended to be C, they now know what to do to correct their code and can safely ignore the C++ related parts of my answer. If by some chance they have posted in the wrong place and were trying to write C++, they also know what they need to do.

Also my reply was a little brief because I was on my phone at the time. Thanks to the fiddly nature of my phone and the limited screen-space, my reply wasn't as comprehensive or detailed as I would have liked.

Seriously, what is your problem? Are you having a bad day or something? Lighten up! :)

Jason, Since this is the C forum, why all the C++ suggestions? Steer him correctly to C solutions.

To me, it looks like he was trying to explain the difference, since the OP doesn't seem to understand. Wouldn't the correct solution be better than the C solution?

EDIT:

Walt, I am aware of which forum this is, but from the OP's post it's kinda ambiguous which language they are trying to write in. Are they trying to write in C or C++? They have an extremely bad mix of both in their code.

And it wouldn't be the first time that a noob incorrectly posted a C++ question in the C forum would it? How many times has C code been incorrectly posted in the C++ forum, or vice versa?

Because of the ambiguity, I simply tried to cover both bases. Does that really deserve being downvoted?

If the OP's code was intended to be C, they now know what to do to correct their code and can safely ignore the C++ related parts of my answer. If by some chance they have posted in the wrong place and were trying to write C++, they also know what they need to do.

Also my reply was a little brief because I was on my phone at the time. Thanks to the fiddly nature of my phone and the limited screen-space, my reply wasn't as comprehensive or detailed as I would have liked.

Seriously, what is your problem? Are you having a bad day or something? Lighten up! :)

K, you beat me to it.

Whats '6' doing in line number 3 ? samohtvii correct it.

All been sorted out. Thanks for the help. The 6 was a typo.
As for the language I got kinda mixed up between what was used in what, it's been a while. It was suppose to be c++ so I've made the corrections.
Thanks

And it wouldn't be the first time that a noob incorrectly posted a C++ question in the C forum would it?

I've done it by mistake several times.

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.