Solved

C++ ifstream error

Posted on 2006-10-20
4
966 Views
Last Modified: 2008-02-01
Heres my code:

using namespace std;                  // Global using directive
#include <iostream>                        // Header file for cout and endl
#include <iomanip>                        // Header file for I/O manipulators

int main()                                    // Start of main() function
{
string source;                              // variable for the input file
int numChar;                              // variable for number of characters

cout << "Enter the name of the source program file now: ";            //Prompt user
cin >> source;
cout << endl << endl;

//-------------------INPUT---------------------

ifstream inputfile (source);


//----------------------------------------------

return 0;                                    // Signal successful program execution

}  // End of main()








Heres my errors:

"Program06.cpp", line 28: Error: The type "std::ifstream " is incomplete.
"Program06.cpp", line 28: Error: The type "std::ifstream " is incomplete.
2 Error(s) detected.



Can anyone tell me how to fix this error

0
Comment
Question by:xneo27
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 500 total points
Comment Utility
#include <fstream>
0
 

Expert Comment

by:alex_kurumpelil
Comment Utility
Was able to compile with VC++ 6.0

#include <iostream>                    // Header file for cout and endl
#include <iomanip>                    // Header file for I/O manipulators
#include <fstream>

using namespace std;               // Global using directive

int main()                              // Start of main() function
{
char szsource[256] = {0};              // variable for the input file
int numChar;                         // variable for number of characters

cout << "Enter the name of the source program file now: ";          //Prompt user
cin >> szsource;
cout << endl << endl;

string source = szsource;
//-------------------INPUT---------------------

ifstream  inputfile;
inputfile.open(source.c_str());


//----------------------------------------------

return 0;                              // Signal successful program execution

}  // End of main()
0
 

Author Comment

by:xneo27
Comment Utility
Thanks cookre, guess it just slipped my mind or I was in too big of a hurry.
0
 
LVL 22

Expert Comment

by:cookre
Comment Utility
That happens to all of us.  
After 36 years programming, I still do it.
But as you gain experience, you immediately recognize the causes of more and more errors.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
zeroMAx challenge 20 76
changePi Challenge 15 75
python question 5 57
index Out OF Range Exception error 4 27
This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now