newfile.c:1:20: fatal error: iostream: No such file or directory

Jan 24, 2017 at 6:27pm
Evertime i try to run or debug my program that pops up.PLS respond ASAP.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main() {
//  Written by: Joe Vardaman
//  Computes the average of a set of values entered by the user, e.g. with
//       10.0  5.0  6.0  9.0  0.0 
//  the average is 7.5 
    int     count;
    float   number, runningTotal ;
    
    runningTotal = 0;
    count = 0;
    cout << "Type the numbers, the last being 0";
    
    cin >> number;
    while  (number != 0) {
        runningTotal = runningTotal + number;
        count = count + 1;
        cin >> number;
    }
    cout << "The average of the " << count << "numbers is " << runningTotal/count;
}
Jan 24, 2017 at 6:41pm
Probably the compiler sees the .c filename extension and tries to compile the code as C rather than C++.

Try renaming the file to newfile.cpp.
Jan 24, 2017 at 6:42pm
Hi @jvardam,
I've seen that problem before, but it really depends on multiple things.
If you have a .c file, then it's not c++, therefore it does not have the iostream library available.
If you work with borland, I think it requires you to include with "iostream.h".
If neither of the above describes your situation, then I don't know what.
Hope I've been at least a little help.
P.S.: I just saw the name of the file in the title. It says "newfile.c", but if you change it to "newfile.cpp", it might work.
Jan 24, 2017 at 7:11pm
when i run it now that i changed the name there are a bunch of problems with it and this is the output:
cd 'C:\Users\josep\OneDrive\Documents\NetBeansProjects\project.cpp'
C:\MINGW\32\mingw32\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MINGW/32/mingw32/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
"/C/MINGW/32/mingw32/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/project.cpp.exe
make.exe[2]: Entering directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/newfile.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/newfile.o.d" -o build/Debug/MinGW-Windows/newfile.o newfile.cpp
newfile.cpp: In function 'int main()':
newfile.cpp:21:82: error: expected '}' at end of input
cout << "The average of the " << count << "numbers is " << runningTotal/count;
^
make.exe[2]: *** [build/Debug/MinGW-Windows/newfile.o] Error 1
make.exe[2]: Leaving directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 5s)
Jan 24, 2017 at 7:22pm
There's nothing wrong with the original code.

However this message
newfile.cpp:21:82: error: expected '}' at end of input
means that somehow the last } at the end of main() on line 22 has been accidentally lost.
Jan 24, 2017 at 7:24pm
So what do i have to do to fix it
Jan 24, 2017 at 7:27pm
i just went ahead and retyped it and now i get this when i try to run it

d 'C:\Users\josep\OneDrive\Documents\NetBeansProjects\project.cpp'
C:\MINGW\32\mingw32\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MINGW/32/mingw32/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
"/C/MINGW/32/mingw32/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/project.cpp.exe
make.exe[2]: Entering directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/project.cpp build/Debug/MinGW-Windows/main.o build/Debug/MinGW-Windows/newfile.o
build/Debug/MinGW-Windows/newfile.o: In function `main':
C:\Users\josep\OneDrive\Documents\NetBeansProjects\project.cpp/newfile.cpp:3: multiple definition of `main'
build/Debug/MinGW-Windows/main.o:C:\Users\josep\OneDrive\Documents\NetBeansProjects\project.cpp/main.cpp:21: first defined here
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/project.cpp.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/josep/OneDrive/Documents/NetBeansProjects/project.cpp'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)
Jan 24, 2017 at 7:30pm
So what do i have to do to fix it

Just make sure your code looks like the original program at the start of this thread.
Jan 24, 2017 at 7:35pm
it is the exact same and still does not run
Jan 24, 2017 at 7:48pm
But which error message does it give?
Jan 24, 2017 at 8:04pm
i said to hell with netbeans and switched to visual studio and it worked just fine. Thanks for the help
Topic archived. No new replies allowed.