如何找到char数组的长度?

时间:2016-02-20 02:48:11

标签: c++ arrays

这是一个java代码。

theurl="http://www.colehersee.com/home/grid/cat/14/?"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage,"html.parser")

for pn in soup.find('table',{"class":"mod_products_grid_listing"}).find_all('span',{"class":"product_code"}):
    pn2 = pn.text
for main in soup.find_all('nav',{"id":"breadcrumb"}):
    main1 = main.text

    print(pn2)
    print (main1)

非常简单的问题,我如何制作java长度属性但是在c ++中?

3 个答案:

答案 0 :(得分:0)

您可以通过传递数组指针来进行函数调用,然后可以通过

检查指针是否为空
sizeof(charArray)/sizeof(charArray[0])

然后你可以试试这个

def split_list(lst, chunks): #print(lst) #print() chunks_yielded = 0 total_sum = sum(lst) avg_sum = total_sum/float(chunks) chunk = [] chunksum = 0 sum_of_seen = 0 for i, item in enumerate(lst): #print('start of loop! chunk: {}, index: {}, item: {}, chunksum: {}'.format(chunk, i, item, chunksum)) if chunks - chunks_yielded == 1: #print('must yield the rest of the list! chunks_yielded: {}'.format(chunks_yielded)) yield chunk + lst[i:] raise StopIteration to_yield = chunks - chunks_yielded chunks_left = len(lst) - i if to_yield > chunks_left: #print('must yield remaining list in single item chunks! to_yield: {}, chunks_left: {}'.format(to_yield, chunks_left)) if chunk: yield chunk yield from ([x] for x in lst[i:]) raise StopIteration sum_of_seen += item if chunksum < avg_sum: #print('appending {} to chunk {}'.format(item, chunk)) chunk.append(item) chunksum += item else: #print('yielding chunk {}'.format(chunk)) yield chunk # update average expected sum, because the last yielded chunk was probably not perfect: avg_sum = (total_sum - sum_of_seen)/(to_yield - 1) chunks_yielded += 1 chunksum = item chunk = [item]

答案 1 :(得分:0)

template <typename T,unsigned S>
inline unsigned arraysize(const T (&v)[S]) { return S; }

编译器将尝试基于模板创建与数组大小匹配的函数。我不赞成答案,请参阅下面的链接,并提供更长的解释。

http://www.cplusplus.com/forum/general/33669/

它不适用于动态分配的数组,但它会给您带来编译错误。有什么东西适用于动态分配的数组吗?

答案 2 :(得分:0)

这样做: for(int a=0; charArray[a] != '\0' ; a++); 这将把charArray的长度存储在'a'