C++问题:比较两个C风格的字符串,哪里错了,输出都是equal

#include
#include
#include
using namespace std;
int main()
{
char s1[]={},s2[]={};
cin.getline(s1,100);
cin.get();
cin.getline(s2,100);
if(strcmp(s1,s2)==0)
{
cout<<"equal"<<endl;
}
else
cout<<"not equal"<<endl;
}

LZ:你定义数组时不初始化大小能够编译过么?应该初始化大小;这是问题一;

 char s1[]={},s2[]={};  应该为:char s1[100]={0};或:char s1[100]; memset(s1,0,sizeof(s1));

其次:cin.get(无参数)没有参数主要是用于舍弃输入流中的不需要的字符,或者舍弃回车,弥补cin.get(字符数组名,接收字符数目)的不足.
你要注意cin.get()的用法;
下面代码已调试好:

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
    {
    char s1[100]={0},s2[100]={0};
    cin.getline(s1,10);
    //cin.get ();
    cin.getline(s2,10);
    if(strcmp(s1,s2)==0)
        {
        cout<<"equal"<<endl;
        }
    else
        cout<<"not equal"<<endl;
    system ("pause");
    return 0;
    }



s1,s2你这样初始化没有分配足够的内存啊,写成s1[100]试试