Thread: Help check my notes.

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    38

    Help check my notes.

    I try to keep up but I must have written down something wrong.

    I get error C2661: 'std::basic_ifstream<_Elem,_Traits>:pen' : no overloaded function takes 0 arguments
    with
    [
    _Elem=char,
    _Traits=std::char_traits<char>
    ]
    What does this mean?

    Code:
    
    #include <iostream>
    #include <fstream>
    using namespace std;
    #include <conio.h>
    #include <string>
    
    int main()
    {
         //Step01: Declare Memory Location
              ifstream InFile;
              ofstream OutFile;
              string MyWord;
         //Step02: Initialize Memory Location
              InFile.open("C:/Temp/TestData1.txt");
              OutFile.open("C:/Temp/TestData1.txt");
         //Step03: Do the Work
    	if (!InFile.open())  //Boolean value (True/False)
    	{
    	     cout << "File does not exist" << endl;
    	     getch();
    	     exit (0);
                    }
    	InFile >> MyWord;
    	cout << MyWord << endl;
    	OutFile << MyWord;
    	InFile >> MyWord;
    	cout << MyWord << endl;
    	OutFile << MyWord;
         //Step04: Wrap up and Exit
              cout << endl;
              getch();
              return 0;
    }
    Any hints?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > if (!InFile.open()) //Boolean value (True/False)
    No parameters here (there should be)
    I rather suspect you want to be testing something else if you're trying to detect whether the file was opened or not.
    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.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > if (!InFile.open()) //Boolean value (True/False)
    Try:
    if (!InFile.is_open()) //Boolean value (True/False)

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    ...or just:

    if(!inFile)

    I rather suspect you want to be testing something else if you're trying to detect whether the file was opened or not.
    I don't understand that comment. It seems to be standard procedure to check if everything is OK when you open a file for reading.
    Last edited by 7stud; 03-15-2005 at 02:46 PM.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I don't understand that comment.
    What he means is the function inFile.open() doesn't check for an open file. All open() does is open a file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 07:07 PM
  3. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  4. A way to check for Win98 or WinXP
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-31-2002, 11:06 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM