n*c 发帖数: 228 | 1 #include
#include
int main(int argc,char* argv[])
{
std::string s;
for(int i=1;i<=argc;i++)
s+=argv[i];
std::cout<
return 0;
}
This one gave me "segmentation fault".
I suppose this is because s is empty
I tried ./prog i love china
Can someone explain? |
t****t 发帖数: 6806 | 2
for (int i=1; i
【在 n*c 的大作中提到】 : #include : #include : int main(int argc,char* argv[]) : { : std::string s; : for(int i=1;i<=argc;i++) : s+=argv[i]; : std::cout<: return 0; : }
|
s*****d 发帖数: 43 | 3 i<=argc
should be
i < argc |
n*c 发帖数: 228 | 4 OH.yeah. argv[0] is also one of argc.Thanks
【在 s*****d 的大作中提到】 : i<=argc : should be : i < argc
|