1,105,633 Community Members

Errors 2446 & 2040

Member Avatar
smco9
Newbie Poster
6 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm getting conversion errors 2446 and 2040 on the red line. Can anyone help me figure out what i've done. I'm new to C++ but I'm expereinced in C# so I do have some foundation. Any help is greatly appreciated!

string GetString(ifstream & fn, string & s, int length)
{
     int charCount;
     char ch;
     s.erase();

     for(charCount = 0; charCount < length; charCount++)
     {
     // Stop if there are fewer characters to be read than expected
     [B]if(fn.peek() == "\n" || fn.peek() == EOF)[/B]
	break;
     else
     {
	ch = fn.get(); // Read next character including blanks
	s = s + ch; // and append it to the string
     } // end else
} // end for that reads in characters
return s;
} // end function GetString
Member Avatar
Ancient Dragon
Achieved Level 70
27,673 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,041 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

Error numbers mean absolutely nothing because they are compiler specific. Post the actual error message for those numbers -- most compilers print messages as well as error numbers.

Member Avatar
smco9
Newbie Poster
6 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

error C2446: '==' : no conversion from 'const char *' to 'int'
1> There is no context in which this conversion is possible

error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'

Member Avatar
Protuberance
Junior Poster in Training
88 posts since Aug 2009
Reputation Points: 67 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
1
 

try to type this

if(fn.peek() == '\n' || fn.peek() == EOF)

Look this http://msdn.microsoft.com/en-us/library/ebe3zf17(VS.80).aspx

peek method returns the next character

Member Avatar
firstPerson
Industrious Poster
4,052 posts since Dec 2008
Reputation Points: 761 [?]
Q&As Helped to Solve: 634 [?]
Skill Endorsements: 24 [?]
 
0
 

"\n" and '\n' are completely different. One is a string literal which is
null terminated while other is a newline character.

Member Avatar
Ancient Dragon
Achieved Level 70
27,673 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,041 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

>>I don't like smiley faces.
:);):D:-O:S:ooh::sweat::icon_eek:

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: