5 Replies - 1147 Views - Last Post: 05 March 2009 - 10:47 AM Rate Topic: -----

#1 emaster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-March 09

c2061 error help!

Posted 05 March 2009 - 02:11 AM

Hey guys, I am doing an assignment for my c++ class and have came across a problem, it seems like it should be simple and easy but I just cant figure it out, here is my code

 void getcodes()
{
string temp;
double size;

do

cin >> temp;

size = temp.length();   // here
if (size == 0)			   // and here is the problem "error c2061 identifier 'size' "
break;

if (validate(temp))
{
codes [count] = temp;
count++; 
}
else
{
cout << "Input sucks. Try again. This time with 10 digits" << endl;
cout << "with 0 or 3 dashes in it," << endl;
cout << "with an optional x at the end " << endl;

}
while (count < 100);
}
 


The error is c2061 identifier error on the lines in these two statements

[code]
size = temp.length();
if (size == 0)
[\code]

my error is : c2061 identifier 'size' from the lines

size = temp.length();
if (size == 0)

This post has been edited by emaster: 05 March 2009 - 02:13 AM


Is This A Good Question/Topic? 0
  • +

Replies To: c2061 error help!

#2 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: c2061 error help!

Posted 05 March 2009 - 02:31 AM

did you forget to put the { } around the do ... while block?
e.g.
do
{   // add?
cin >> temp;

size = temp.length();   // here
if (size == 0)			   // and here is the problem "error c2061 identifier 'size' "
break;

if (validate(temp))
{
codes [count] = temp;
count++;
}
else
{
cout << "Input sucks. Try again. This time with 10 digits" << endl;
cout << "with 0 or 3 dashes in it," << endl;
cout << "with an optional x at the end " << endl;

}
} // add}
while (count < 100);

This post has been edited by horace: 05 March 2009 - 02:31 AM

Was This Post Helpful? 0
  • +
  • -

#3 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2034
  • View blog
  • Posts: 5,436
  • Joined: 27-December 05

Re: c2061 error help!

Posted 05 March 2009 - 08:51 AM

View Postemaster, on 5 Mar, 2009 - 04:11 AM, said:

error c2061 identifier 'size'

It would help to diagnose if you would post the entire error message instead of a snippet.

horace is correct that the missing braces will cause an error, but I don't think that will solve this particular error. There may be an ambiguity between your "double size" variable and another size variable defined elsewhere, like in a header that you are including. Try renaming your "size" to, say, mySize or _size, etc.
Was This Post Helpful? 0
  • +
  • -

#4 Notorion   User is offline

  • D.I.C Regular

Reputation: 35
  • View blog
  • Posts: 378
  • Joined: 17-February 09

Re: c2061 error help!

Posted 05 March 2009 - 09:19 AM

Stilt is referring to a scoping error of naming your variable size, which I do not think is the case. Generally compilers can figure out scopes pretty well due to stack they have.

 void getcodes()
{
string temp;
//double size;  //old code
int size;  //I found when returning length from the string class, int works pretty well when it has to convert it to int
			 //rather than convert it to a double.  (added)

do
{  //start do while bracket (added)

cin >> temp;

size = temp.length();   // here
if (size == 0)			   // and here is the problem "error c2061 identifier 'size' "
break;

if (validate(temp))
{
codes [count] = temp;
count++;
}
else
{
cout << "Input sucks. Try again. This time with 10 digits" << endl;
cout << "with 0 or 3 dashes in it," << endl;
cout << "with an optional x at the end " << endl;
}

}  //end do while bracket (added)
while (count < 100);
}



See if that will work for you, because I'm thinking it has something to do with what the string class returns, and then what you store it in. If it doesn't work, please post back.
Was This Post Helpful? 0
  • +
  • -

#5 emaster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-March 09

Re: c2061 error help!

Posted 05 March 2009 - 10:34 AM

Thanks horace, the brackets did it. I actually copied the whole error notice, but since I couldn't highlighted it I just typed it out.

It was just the brackets around the do. Thanks!
Was This Post Helpful? 0
  • +
  • -

#6 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: c2061 error help!

Posted 05 March 2009 - 10:47 AM

View Postemaster, on 5 Mar, 2009 - 04:34 PM, said:

Thanks horace, the brackets did it. I actually copied the whole error notice, but since I couldn't highlighted it I just typed it out.

It was just the brackets around the do. Thanks!

good to hear it is now working!
It would be wise to make size an int as Notorion indicated so it is the correct type for temp.length().
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1