小编TT1*_*T12的帖子

将向量传递给函数c ++

我有一个main.cpp test.h和test.cpp>我试图通过我的矢量,所以我可以在test.cpp中使用它但我不断收到错误.

   //file: main.cpp
    int main(){
        vector <Item *> s;
         //loading my file and assign s[i]->name and s[i]-address
         tester(s);
    }

    //file: test.h
    #ifndef TEST_H
    #define TEST_H
    struct Item{
        string name;
        string address;
    };
    #endif

    //file: test.cpp
    int tester(Item *s[]){
        for (i=0; i<s.sizeof();i++){
            cout<< s[i]->name<<"  "<< s[i]->address<<endl;
        }
        return 0;
    }



    ---------------errors--------
    In file included from main.cpp:13:
    test.h:5: error: âstringâ does not name a type
    test.h:6: error: âstringâ does not name a type
    main.cpp: In function âint main()â:
    main.cpp:28: error: cannot …
Run Code Online (Sandbox Code Playgroud)

c++ vector parameter-passing

5
推荐指数
1
解决办法
2万
查看次数

python索引错误:列表中的2个列表

def main():
    L=[]
    list1=[5,1,3]
    list2=[4,6,2]
    L.append(list1)
    L.append(list2)
    f(L)

def f(L):
    for i in range(6)
         print L[i]



IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)

python list

2
推荐指数
1
解决办法
121
查看次数

string.compare for c ++

我要求用户输入一个单词然后让我的程序将它与输入的.txt文件进行比较,但即使我在data.txt中输入一个单词,它仍然执行false.

//------------in my data.txt---------
// Banana Bed Today
// Apples Chair Window
// Corn Tomorrow Hive

string testData;
  cout<<"enter Data: ";
  cin>>testData;
  for(i=0; i<s.size()-1; i++){
    if (testData.compare(s[i]->name) == 0)
      cout<<"Right\n";
    if (youkno.compare(s[i]->name) != 0)
        cout<<"Wrong\n";
  }
Run Code Online (Sandbox Code Playgroud)

如果我提示Banana然后输出出错的错误

c++ io compare

0
推荐指数
1
解决办法
151
查看次数

标签 统计

c++ ×2

compare ×1

io ×1

list ×1

parameter-passing ×1

python ×1

vector ×1