Thread: I cant figure out what is wrong with this

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    13

    I cant figure out what is wrong with this

    Hello, I cant figure out what is wrong with this.

    Code:
      
    
    
    #include "stdafx.h"
    
    #include <iostream> 
    #include <iomanip>
    #include <fstream>
    #include <string>
    #include <stdlib.h>
    
    using namespace std;
    //#include "songs.h"
    
    
    //prototypes
    void getData();
    void printData();
    
    
    //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    
    int main()
    {
    	int many = 0; //how many things are in the file
    	string filename;
    	char choice;
    	
    	cout <<"Please enter the filename holding the initial database: ";
    	getline(cin, filename);
    	cout << endl;
    
    	getData();
    
    	if (many > 0)
    	{
    
    		cout << "Initial DB: " << endl;
    		cout << endl;
    		cout << endl;
    		printData();
    
    
    		cout << endl;
    		cout << endl;
    		cout << "Please choose one: " << endl;
    		cout << "1. Print out Song Times" << endl;
    		cout << "2. Determine the total playing time of the playlist " << endl;
    		cout << "3. Quit " << endl;
    		cout << endl;
    
    		cin >> choice;
    		cout << endl;
    		cout << endl;
    
    		while (cin)
    		{
    			if (choice == '1')
    			{
    				//printData()
    				cout << "Sorry, can't handle yet..." << endl;
    			}
    
    			else if (choice == '2')
    			{
    				//songs.two ()
    				cout << "Sorry, can't handle yet..." << endl;
    			}
    
    			else if (choice == '3')
    			{
    			exit(1);
    			}
    
    			else 
    			{
    				cout << "Invalid choice -- Choose again" << endl;
    
    				cout << endl;
    				cout << endl;
    				cout << "Please choose one: " << endl;
    				cout << "1. Print out a list of the times of the songs " << endl;
    				cout << "2. Determine the total playing time of the playlist " << endl;
    	                       cout << "3. Quit " << endl;
    				cout << endl;
    
    				cin  >> choice;
    			}//else
    
    		}//while
    	}//if
    
    	else 
    	{
    		cout << "Empty data file -- program terminating..." << endl;
    
    		cout << endl << endl 
    			 <<"End program..." << endl << endl;
    	}//else
    
      return 0;
    
    }//main
    
    
    //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    
    void getData()
    {
    	ifstream
    		InStream;
    
    	 int mins;
    	 int secs;
    	 string filename;
    	  
    
    	 cout << endl;
    	 cout << "Attempting to open the file " << filename << endl;
    
    	 InStream.clear();
    	 InStream.open(filename.c_str(), ios::in);
    
    	 if(InStream.fail() )
    	 {
    		 cout << "ERROR: input file called " << filename
    			  << "didn't open " << endl;
    		 cout << endl;
    		 cout << "Program terminating ... " << endl;
    		 exit(-1);
    	 } //if fail
    
    	 while (InStream)
    	 {
    		 getline (InStream, mins, ':');
    		InStream >> secs;
    	 }
     
    	 
    
    }//getData
    
    
    //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    
    void printData() 
    {
    	int mins;
    	int secs;
    
    	cout << " Song Times " << endl;
    	cout << "--------------" << endl;
    
    	for (int i=0; i = i; i++)
    	{
    		cout << mins << ":" <<  secs << endl;
    	}//for
    
    
    }//printData
    There are three errors:

    error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const
    _E)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class std::basic_ifstream<char,struct std::char_traits<char> >'

    error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const
    _E)' : could not deduce template argument for 'class std::basic_string<_E,_Tr,_A> &' from 'int'

    error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : ex
    pects 2 arguments - 3 provided

    c:\program files\microsoft visual studio\vc98\include\string(145) : see declaration of 'getline'
    Error executing cl.exe.

    Any Suggestions. Thank you.

    Angel

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> getline (InStream, mins, ':');

    look closely at the error again:

    'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const
    _E)' : could not deduce template argument for 'class std::basic_string<_E,_Tr,_A> &' from 'int'
    getline is expecting an std::string.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Formatted input is tricky in C++, and as said above, the getline function only operates on std::string's. It can be helpful to use C's family of scanf functions for formatted input. For example: we can do this:

    Code:
    	int a, b;
    	string line;
    
    	getline(cin, line);
    	sscanf(line.c_str(), "%d:%d", &a, &b);
    
    	cout 
    		<< "Mintues: " << a << endl 
    		<< "Seconds: " << b << endl;
    Output:

    12:45
    Mintues: 12
    Seconds: 45

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    13
    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! I cannot figure out what I'm doing wrong here!
    By chsindian595 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 03:18 AM
  2. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM
  3. please help, i can't figure out what's wrong
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2002, 09:13 PM
  4. What is wrong here?????
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2002, 10:51 AM
  5. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 08:14 AM