Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Problems with cin::getline
Problems with cin::getline [message #831628] Thu, 29 March 2012 05:45 Go to next message
Ali Aliev is currently offline Ali AlievFriend
Messages: 3
Registered: March 2012
Junior Member
I use CDT Internal Builder and MS Visual C++ Toolchain in my project in Eclipse. The problem is that the compiler swears:

Invalid arguments '
Candidates are:
std::basic_istream<char,std::char_traits<char>> & getline(char *, ?)
std::basic_istream<char,std::char_traits<char>> & getline(char *, ?, char)
'

when I'm tapping something like this:

#include <fstream>
using namespace std;

int main()
{
fstream fin;
char buf[256];

fin.open("in.txt", fstream::in);
fin.getline(buf, 256); // !!!!!

return 0;
}

What is the problem?
Re: Problems with cin::getline [message #832515 is a reply to message #831628] Fri, 30 March 2012 08:29 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
The answer is in the error message. getline() wants as first argument char*. But you are using char. You must replace buf with &buf.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Problems with cin::getline [message #832581 is a reply to message #832515] Fri, 30 March 2012 10:09 Go to previous messageGo to next message
Ali Aliev is currently offline Ali AlievFriend
Messages: 3
Registered: March 2012
Junior Member
Axel Mueller wrote on Fri, 30 March 2012 12:29
The answer is in the error message. getline() wants as first argument char*. But you are using char. You must replace buf with &buf.

It isn't that simple. buf is char*, see the declaration.
Re: Problems with cin::getline [message #832744 is a reply to message #832581] Fri, 30 March 2012 14:33 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
It isn't that simple. buf is char*, see the declaration.

No. buf is declared as char[]! It is an array of char and not a pointer to a char. That is something different.
http://c-faq.com/aryptr/aryptrequiv.html


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Problems with cin::getline [message #832969 is a reply to message #832744] Fri, 30 March 2012 20:00 Go to previous messageGo to next message
Ali Aliev is currently offline Ali AlievFriend
Messages: 3
Registered: March 2012
Junior Member
buf is the pointer that points at the first element of the array of characters, as I'm teached to think.
Anyway, it turns out the problem is different: it has something to do with CODAN code analyser. If you want to read more about this, I could give you a link in private (I'm still not allowed to post links).
The problem was solved by switching the level of warning of 'Invalid arguments' from 'Error' to 'Warning'. It's not good, but it works.
Re: Problems with cin::getline [message #834716 is a reply to message #832969] Mon, 02 April 2012 09:49 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Ali Aliev wrote on Fri, 30 March 2012 22:00
buf is the pointer that points at the first element of the array of characters, as I'm teached to think.

You are completely right. I was somehow confused.


Quote:
Anyway, it turns out the problem is different: it has something to do with CODAN code analyser.

Yes, I know that it is a CODAN error or to be more precise it is a failure of the indexer (on which CODAN relies). I could reproduce your problem locally.

Quote:
std::basic_istream<char,std::char_traits<char>> & getline(char *, ?)

You might have noticed that question mark in the signature above. That means the indexer could not resolve the type of the second argument. According to the fstream header (select getline and then press F3 to get the definition) it should be streamsize. However, when I want to see the definition of streamsize the indexer presents me 2 alternatives. The one from the C++ std headers and another one from a STLport header (I have installed STLport in my project). In the STLport header the typedef for streamsize (ptrdiff_t) fails.
I guess you might have a similar problem (two concurring definitions of streamsize).


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Problems with cin::getline [message #841385 is a reply to message #834716] Wed, 11 April 2012 08:29 Go to previous message
Arkady Lokhovitskiy is currently offline Arkady LokhovitskiyFriend
Messages: 1
Registered: April 2012
Junior Member
Hi,

I don't think a double definition of streamsize can explain an indexer behavior. I ran into the same problem few times already. Using a local instance of Eclipse Indigo on Mac as IDE for Linux RT development make me disappointed with the present CODAN quality. I managed to add remote headers to a project and the indexer took them well from a Linux server. CODAN way making its code analysis also well till the issue of the topic. A very simple example of a code with demonstrates the problem. with b - no error, with orbitTimestamp - wrong argument. Castig is added to enforce somehow CODAN to treat the argument as needed.




uint32_t orbitTimestamp;
		
char * b;

infile.read(b,   sizeof(uint32_t));
			
infile.[color=red]read[/color](reinterpret_cast<char *>(&orbitTimestamp),   sizeof(uint32_t));



IMHO, this is definitely a bug in CODAN.
Previous Topic:build multiple artifact?
Next Topic:Problem with debugging
Goto Forum:
  


Current Time: Fri Apr 19 23:38:34 GMT 2024

Powered by FUDForum. Page generated in 0.03226 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top