最好的方法是使用矢量。 最好 Kai-Uwe Bux 为什么? - A:因为它搞砸了人们通常阅读文字的顺序。 问:为什么这么糟糕? A:热门帖子。 Q :usenet和电子邮件中最烦人的事情是什么? I''m creating a class BookType that will store information about books. Eachbook type can have up to 4 authors.I defined a new type for an array of char:typedef char array4_t[25];This will hold 25 characatersI declared a 2 dimensional array of char in BookType:char m_authors[4][25];I could have used vector but this just a practical exercise.I have a SetAuthors function which sets the authors which accepts a pointerto a pointer toi char (char**). It works fine.I also have a function GetAuthors that returns a pointer to array4_t:array4_t* BookType::GetAuthors(){return m_authors;}In my test program I want to loop through the array of strings and print theauthors. I''ve done this but it doesn''t work well:array4_t* authors = books[i]->GetAuthors();while (*authors != NULL){printf(" %s ", authors);authors++;}This goes into an infinite loop. Not sure why.Can someone please tell me the best way to return a pointer to an array ofchar and how to iterate through the array without using vector (or anotherSTL container)? 解决方案MikeThe best way is to use a vector.BestKai-Uwe BuxWhy?--A: Because it messes up the order in which people normally read text.Q: Why is it such a bad thing?A: Top-posting.Q: What is the most annoying thing on usenet and in e-mail? 这篇关于指向char数组的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 05:43