Getline error, help.

I keep getting an error saying it can't deduce the argument for the getline or something of that nature. I don't understand what's wrong with the program. I'm trying to read data from an input.txt file, so maybe there's an issue with the passing of the data?





#include "Project2.h"

void weatherSummary ( string input, string output )
{
ifstream in("input.txt"); // read the data from the input file
ofstream out("output.txt"); // send my data to an output text

string name;
int latitude;
int longitude;
int elavation;
int TPCP;
int MNTM;
in.ignore(5000, '\n'); //ignore the header

readData( in, name, elavation, latitude, longitude, TPCP, MNTM );

while( !in.fail() )
{
out << name << "," << elavation << "," << latitude << "," << longitude
<< "," << TPCP << "," << MNTM << endl;

readData( in, name, elavation, latitude, longitude, TPCP, MNTM );

}


}


void readData(ifstream& in, string& name, int& elavation, int& latitude,
int& longitude, int &TPCP, int &MNTM )
{
string junk;
getline( in, junk, ',' );//read from in, store in junk and stop
//at the comma - and get rid of the comma in the process
getline( in, name, ',' );
getline ( in, elavation, ',' );
in.ignore( 500, ',');//ignore the list of namespace
in >> latitude;
in >> longitude;
in.ignore( 500, ',' );//ignore the date line
getline( in, TPCP, ',');//read the TPCP data
in.ignore(500, ',');//ignore the missing line
in.ignore(500, ',');//ignore the consecutive line
getline (in, MNTM, ',');//get the data for temperature
in.ignore (5000, '\n' );// ignore the rest of the line

}

int main ()
{
weatherSummary();
readData();

return 0;

}
> it can't deduce the argument for the getline or something of that nature.
If you don't understand the error message, post it verbatim.
Also, it should tell you the line number.

> #include "Project2.h"
¿making sure that we couldn't compile your snip?
Getline reads from the stream into a string.
string& name is suitable.
But int& elavation and int &TPCP and int &MNTM are not - because they are integers, not strings.

You could use something like
 
in >> elavation; in.ignore(100, ',');
instead of
 
getline ( in, elavation, ',' ); 

this is my header

#include <fstream>
#include <iostream>
#include <string>


using std::string;
using std::ifstream;
using std::ofstream;
using std::cout;
using std::endl;
using std::getline;


int longitude;
int latitude;
int name;
int elavation;
int MNTM;
int TPCP;


void readData(ifstream& in, string &name, double& elavation, double& latitude, double& longitude,
int &TPCP, int &MNTM );

void weatherSummary ( string , string );
this is the error messages

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\string(73): note: see declaration of 'std::getline'
.\Project2.cpp(53): error C2660: 'weatherSummary': function does not take 0 arguments
.\Project2.cpp(54): error C2661: 'readData': no overloaded function takes 0 arguments

the getline has the same error I posted for every where in my code I used getline, I don't understand what these error messages mean?

weatherSummary(); This is you trying to call the function weatherSummary, but look at that function:
void weatherSummary ( string input, string output )
You're calling it wrong. It takes two parameters. How many parameters are you trying to call it with? Zero.

readData(); This is you trying to call the function readData, but look at that function:
1
2
void readData(ifstream& in, string& name, int& elavation, int& latitude, 
int& longitude, int &TPCP, int &MNTM )

You're calling it wrong. Look at all the parameters it takes. How many parameters are you trying to call it with? Zero.
Last edited on
I guess I don't know how to call a function properly. I'll look in my textbook and figure out how to do so.
why wouldn't the string and int be parameters though?
Here is how to call a function that takes one parameter:
function( some_parameter);
As you say, you definitely need to go back to basics and learn how to call a function.
Last edited on
I redid my code, and the errors I'm getting now are

.\Project2.cpp(16): error C2275: 'std::string': illegal use of this type as an expression
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xstring(2603): note: see declaration of 'std::string'
.\Project2.cpp(16): error C2062: type 'int' unexpected
.\Project2.cpp(23): error C2275: 'std::string': illegal use of this type as an expression
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xstring(2603): note: see declaration of 'std::string'
.\Project2.cpp(23): error C2062: type 'int' unexpected
.\Project2.cpp(54): error C2065: 'in': undeclared identifier
.\Project2.cpp(54): error C2275: 'std::string': illegal use of this type as an expression
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xstring(2603): note: see declaration of 'std::string'
.\Project2.cpp(54): error C2062: type 'int' unexpected




my code now is this

#include "Project2.h"

void weatherSummary ( string inputfile, string outputfile )
{
ifstream in("input.txt"); // read the data from the input file
ofstream out("output.txt"); // send my data to an output text file

string name;
int latitude;
int longitude;
int elavation;
int TPCP;
int MNTM;
in.ignore(5000, '\n'); //ignore the header

readData( in, string &name, int& elavation, int& latitude, int& longitude, int& TPCP, int& MNTM );

while( !in.fail() )
{
out << name << "," << elavation << "," << latitude << "," << longitude
<< "," << TPCP << "," << MNTM << endl;

readData( in, string& name, int& elavation, int& latitude, int& longitude, int& TPCP, int& MNTM );

}


}


void readData(ifstream& in, string &name, int& elavation, int& latitude,
int& longitude, int& TPCP, int& MNTM )
{
string junk;
getline( in, junk, ',' );//read from in, store in junk and stop
//at the comma - and get rid of the comma in the process
getline( in, name, ',' );
in >> elavation;
in.ignore( 500, ',');//ignore the list of namespace
in >> latitude;
in >> longitude;
in.ignore( 500, ',' );//ignore the date line
in >> TPCP; //read the TPCP data
in.ignore(500, ',');//ignore the missing line
in.ignore(500, ',');//ignore the consecutive line
in >> MNTM;//get the data for temperature
in.ignore (5000, '\n' );// ignore the rest of the line

}

int main ()
{
weatherSummary( "US_partial.cvs", "output.cvs");
readData( in, string& name, int& elavation, int& latitude, int& longitude, int& TPCP, int& MNTM );

return 0;

}
Can you please use code tags when posting code, to make it readable? You've surely noticed other people doing it in their replies to you.

http://www.cplusplus.com/articles/z13hAqkS/
sorry guys, this is my code in the correct format, I apologize for not formatting it correctly.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "Project2.h"

void weatherSummary ( string inputfile, string outputfile )
{
	ifstream in("input.txt"); // read the data from the input file
	ofstream out("output.txt"); // send my data to an output text file

	string name;
	int latitude;
	int longitude;
	int elavation;
	int TPCP;
	int MNTM;
	in.ignore(5000, '\n'); //ignore the header
		
	 readData( in, string &name, int& elavation, int& latitude,  int& longitude, int& TPCP, int& MNTM );

	while( !in.fail() )
	{
		out << name << "," << elavation << "," << latitude << "," << longitude 
		<< "," << TPCP << "," << MNTM << endl;
		
		readData( in, string& name, int& elavation, int& latitude,  int& longitude, int& TPCP, int& MNTM );

	}
	

}


void readData(ifstream& in, string &name, int& elavation, int& latitude, 
	int& longitude, int& TPCP, int& MNTM )
{
	string junk;
	getline( in, junk, ',' );//read from in, store in junk and stop
	//at the comma - and get rid of the comma in the process
	getline( in, name, ',' );
	in >> elavation;
	in.ignore( 500, ',');//ignore the list of namespace
	in >> latitude;
	in >> longitude;
	in.ignore( 500, ',' );//ignore the date line 
	in >> TPCP; //read the TPCP data 
	in.ignore(500, ',');//ignore the missing line
	in.ignore(500, ',');//ignore the consecutive line
	in >> MNTM;//get the data for temperature
	in.ignore (5000, '\n' );// ignore the rest of the line

}

int main ()
{
	weatherSummary( "US_partial.cvs", "output.cvs");
	readData( string& name, elavation, latitude, longitude, TPCP, MNTM );
	
	return 0;
	
}

Thanks! :)

Those error messages are telling you which lines your errors are on, and the ones on lines 16, 23 and 54 should be pretty easy to see. Are those lines supposed supposed to be declaring a function, or calling it? Because parts of them look like a declaration, and parts like a call.

I suspect you've copied and pasted that line, and not edited it carefully.

It seems to me that you might have not understood how to call functions at all. If that's the case, then the best advice I can give you is to go back to your textbook and study that section until you understand it completely. Because it's absolutely crucial to C and C++ programming.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <fstream>
#include <iostream>
#include <string>


using std::string;
using std::ifstream;
using std::ofstream;
using std::cout;
using std::endl;
using std::getline;


int longitude;
int latitude;
int name;
int elavation;
int MNTM;
int TPCP;


void readData(ifstream& in, string &name, double& elavation, double& latitude, double& longitude,
	int &TPCP, int &MNTM );

void weatherSummary ( string , string );



here's my header in the correct format as well
Topic archived. No new replies allowed.