Solved

C++ ifstream error

Posted on 2006-10-20
4
971 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
ID: 17775441
#include <fstream>
0
 

Expert Comment

by:alex_kurumpelil
ID: 17775908
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
ID: 17777135
Thanks cookre, guess it just slipped my mind or I was in too big of a hurry.
0
 
LVL 22

Expert Comment

by:cookre
ID: 17777893
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …

821 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