C ++查找i更改为ISO [英] C++ Lookup of i changed for ISO

查看:114
本文介绍了C ++查找i更改为ISO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字典的以下代码。

  void Dictionary :: translate(char out_s [],const char [])
{

for(int i = 0; i {
if(strcmp(englishWord [i],s) = 0)
break;
}
if(i strcpy(out_s,elvishWord [i]);

这给出了错误 c $ c>并提到如果我使用 -fpermissive ,代码将被接受。



任何想法?



不要for iso(也许读取整个错误信息...

/ strong>),但是对于ISO C ++。问题是 i 变量的范围只是 for 循环(因为它的定义在初始化循环)。因为你似乎想在循环外使用它,所以这样声明:

  int i; 
for(i = 0; i // ...
}

do_safe_stuff_with // valid


I have the following code for a dictionary.

void Dictionary::translate(char out_s[], const char s[])
{

for (int i=0;i<numEntries;i++)
{
   if (strcmp(englishWord[i], s)==0)
       break;
}
if (i<numEntries)
strcpy(out_s, elvishWord[i]);

which gives me the error name lookup of i changed for iso and mentions that the code will be accepted if i use -fpermissive. If i try and initialize the variable outside the for loop it generates a whole load of errors.

Any ideas?

Thanks in advance.

解决方案

Not "for iso" (perhaps read the entire error message...), but for ISO C++. The problem is that the scope of the i variable is only the for loop (since its definition is inside the initialization of the loop). Since it seems you want to use it outside the loop, declare it like so:

int i;
for (i = 0; i < foo; i++) {
    // ...
}

do_safe_stuff_with(i); // valid

这篇关于C ++查找i更改为ISO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆