fatal error: iostream: No such file or directory

This is a discussion on fatal error: iostream: No such file or directory within the C Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; //Added // #include <iomanip> int main() { int product, quantity; double total = 0.0; ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    14

    fatal error: iostream: No such file or directory

    Code:
    #include <iostream>
    using namespace std; //Added
    //
    #include <iomanip>
    
    
    
    
    int main()
    {
    int product, quantity;
    double total = 0.0;
    
    
    // display headers
    cout << "Enter pairs of item numbers and quantities."
    << "Enter -1 for the item number to end input.\n";
    cin >> product;
    
    
    while ( product != -1 )
    {
    cin >> quantity;
    switch ( product ) // switch statment nested in while
    {
    case 1:
    total += quantity * 2.98;
    break; // necessary to exit switch
    case 2:
    total += quantity * 4.50;
    break; //exit switch
    case 3:
    total += quantity * 9.98;
    break; // exit switch
    case 4:
    total += quantity * 4.49;
    break; // exit switch
    case 5:
    total += quantity * 6.87;
    break; // exit switch
    default: // catch all other characters
    cout << "Invalid product code: " << product
    << "\n Quantity: " << quantity << '\n';
    break;// optional; will exit switch anyway
    } // end switch
    
    
    cout << "Enter pairs of item numbers and quantities.\n"
    << "Enter -1 for the item number to end input: ";
    cin >> product;
    } // end while
    
    
    cout << setiosflags( ios::fixed | ios::showpoint )
    << "The total retail value was: " << setprecision( 2 )
    << total << endl;
    
    
    return 0; // indicate successful termination
    } // end function

    i get "C:\Users\Yeoh Wei Liang\Documents\online retailer sells\Untitled2.c|1|fatal error: iostream: No such file or directory|"
    when i compile my program.
    Help me...

  2. #2
    Registered User
    Join Date
    Sep 2011
    Posts
    14
    I using code::block and MinGW

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    > Untitled2.c
    This is a C program, not a C++ program.
    Name your file as prog.cpp
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    14
    my lecturer ask us to do c program,not c++
    is there anyway to write the c program have the same function with iostream and iomanip?
    Last edited by yeohwl91; 10-02-2011 at 01:09 AM.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    Use fgets(chararray,chararraysize,stdin) with sscanf for cin and puts/printf for cout.

  6. #6
    Registered User
    Join Date
    Sep 2011
    Posts
    14
    how should i write for
    Code:
    cout << setiosflags( ios::fixed | ios::showpoint ) << "The total retail value was: " << setprecision( 2 ) << total << endl;


    Last edited by yeohwl91; 10-02-2011 at 01:40 AM.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    > my lecturer ask us to do c program,not c++
    > is there anyway to write the c program have the same function with iostream and iomanip?
    No, because that would be a C++ program, and what you wrote is a C++ program.
    You don't write a C program just by naming the file prog.c

    Even if by some pure stroke of luck your compiler managed to compile it, it would STILL be a C++ program. Trying to compile it with another C compiler would just show you that it was wrong.

    Formatted printing in C is stdio.h and printf()

    You might want a different lecturer if they've been vague on the boundaries between C and C++.
    Or at least a wider range of source material to verify whatever they're saying.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    Quote Originally Posted by yeohwl91 View Post

    printf ("the total retail value was:%d", (what should i write here))
    printf ("the total retail value was:%.2f", adoubleorafloatvalue);

  9. #9
    Registered User
    Join Date
    Sep 2011
    Posts
    14
    thanks to BillyTKid. My problem solved.

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by yeohwl91 View Post
    my lecturer ask us to do c program,not c++
    is there anyway to write the c program have the same function with iostream and iomanip?
    cin, cout, iostream, iomanip, etc. are all C++ code. C and C++ are two completely separate languages. While some compilers will do both, you will be in for one rude awakening on a C-only compiler... almost every other line in your source code is going to report a syntax error...

    You can put some (but not all C stuff into a C++ program... but you can't put ANY C++ into a C program.

    Do you not have textbooks you can refer to?

  11. #11
    Registered User
    Join Date
    Oct 2011
    Location
    india
    Posts
    18
    u have done this program in cpp and saved it with extension ".c" . Two solutions exist:
    1).save the program as pgname.cpp
    2).
    (i)use header file #include<stdio.h>
    (ii)use printf() in place of cout
    (iii)use scanf() in place of cin
    the resultant code is as follows:
    Code:
    #include <stdio>
    
    using namespace std; //Added
    
    //
    
    #include <iomanip>
    
     
    
     
    
     
    
     
    
    int main()
    
    {
    
    int product, quantity;
    
    double total = 0.0;
    
     
    
     
    
    // display headers
    
    printf("Enter pairs of item numbers and quantities.\n Enter -1 for the item number to end input.\n");
    
    scanf("%d",&product);
    
     
    
     
    
    while ( product != -1 )
    
    {
    
    scanf("%d",&quantity);
    
    switch ( product ) // switch statment nested in while
    
    {
    
    case 1:
    
    total += quantity * 2.98;
    
    break; // necessary to exit switch
    
    case 2:
    
    total += quantity * 4.50;
    
    break; //exit switch
    
    case 3:
    
    total += quantity * 9.98;
    
    break; // exit switch
    
    case 4:
    
    total += quantity * 4.49;
    
    break; // exit switch
    
    case 5:
    
    total += quantity * 6.87;
    
    break; // exit switch
    
    default: // catch all other characters
    
    printf("Invalid product code: %d \n Quantity: %d",product,quantity);
    
    break;// optional; will exit switch anyway
    } // end switch
     
    
     
    cout << "Enter pairs of item numbers and quantities.\n"//change these places also
    
    << "Enter -1 for the item number to end input: ";
    cin >> product;
    } // end while
     
     
    cout << setiosflags( ios::fixed | ios::showpoint )
    << "The total retail value was: " << setprecision( 2 )
    << total << endl;
     
     
    return 0; // indicate successful termination
    } // end function

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by vikasvijayan View Post
    u have done this program in cpp and saved it with extension ".c" . Two solutions exist:
    1).save the program as pgname.cpp
    2).
    (i)use header file #include<stdio.h>
    (ii)use printf() in place of cout
    (iii)use scanf() in place of cin
    the resultant code is as follows:
    Which is STILL not C source code. A C compiler will puke on the first line... C doesn't know know either of your headers, it doesn't know the using or namespace keywords and it hasn't got the first clue what to do with cout ...

    Both of you need to get your heads into C tutorials... and both of you need to learn the difference between C and C++ ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fatal error C1083: Cannot open include file:
    By bodhankaryogesh in forum Windows Programming
    Replies: 14
    Last Post: 03-31-2008, 07:02 AM
  2. (Error message) Fatal: Unable to open file 'C.OBJ'
    By drojen in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2006, 12:05 AM
  3. [Linker Fatal Error] Fatal: Expected a file name
    By Checco in forum C++ Programming
    Replies: 1
    Last Post: 07-27-2005, 05:34 AM
  4. fatal error C1004: unexpected end of file found
    By Gutty in forum C++ Programming
    Replies: 1
    Last Post: 08-11-2003, 09:58 PM
  5. Weird fatal error, header file related
    By alkis_y3k in forum C++ Programming
    Replies: 2
    Last Post: 12-26-2002, 08:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21