【发布时间】:2015-04-17 09:10:25
【问题描述】:
给定一个字符串数组,我需要找出其中的字符串数。
我关注了this
但如果我将它传递给函数,这将不起作用。
这是我尝试过的代码
#include<string>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int f1(char* input1[])
{
string s="";
cout<<sizeof(input1)<<endl; //print 4
cout<<sizeof(char*)<<endl; //print 4
int l=sizeof(input1) / sizeof(char*);
//giving l=1 here but should be 8
}
int main()
{
char *str2[]={"baba","sf","dfvf","fbfebgergrg","afvdfvfv","we","kkhhff","L"};
int l=sizeof(str2) / sizeof(char*);
cout<<l<<endl; //print 8
cout<<sizeof(str2)<<endl; //print 32
cout<<sizeof(char*)<<endl; //print 4
f1(str2);
}
【问题讨论】:
-
你知道你必须为哪个编译器解决这个问题吗?