为啥VS2017用strcmp比较输入后永远false
c语言吧
全部回复
仅看楼主
level 2
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(int argc, char ** argv)
{
char pn[100];
char bijiao[100] = { "hello" };
char pr[100], br[100];
printf("Please Input:hello");
cin >> pn;
//if (pn == "hello")
if (strcmp(bijiao, pn))
{
printf("good!");
}
else
{
printf("no!");
}
getchar();
system("pause");
return 0;
}
即使是输入了指定字符串,仍然是false...
2017年09月22日 13点09分 1
level 9
字符串一致返回0,不一致返回非0
2017年09月22日 13点09分 3
level 10
问题就出现了你写的是C++程序,你不用字符串重载的比较运算符,而用C语言的字符串操作函数?
2017年09月22日 14点09分 4
然而我就是学C的,因为VC新的用scanf会报错,所以被迫转移到了cin.....
2017年09月22日 22点09分
scanf_s又似乎编译不通过....
2017年09月22日 22点09分
level 10
你这样cin printf 混合使用的风格很糟糕啊
2017年09月22日 15点09分 5
level 10
我觉得你可能只是图C++的输入流方便而完全不会C++?我觉得你应该在学习阶段不要混合使用两种东西
2017年09月22日 15点09分 6
1