我有一个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) 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) 我要求用户输入一个单词然后让我的程序将它与输入的.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然后输出出错的错误