问题描述
- c++问题 指向字符串的指针
-
#include "stdafx.h"
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *s = "Hello";
char *t = "World";
int i = strcmp(s, t);
if (i > 0)
cout << "s>t" << endl;
else if (i < 0)
cout << "s<t" << endl;
else
cout << "s=t" << endl;
int j = strlen(s);
cout << endl;
cout << "字符串s的长度为:" << j << endl;
return 0;
}
Error 2 error C2001: newline in constant 22 1Error 3 error C2143: syntax error : missing ';' before 'return' 23 1
Warning 1 warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss求高手改错,不胜感激!
解决方案
解决方案二:
用的什么编译器,VC6的话就把所有的变量声明都写在前面
解决方案四:
#include "stdafx.h"
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *s = "Hello";
char *t = "World";
int i = strcmp(s, t);
if (i > 0)
cout << "s>t" << endl;
else if (i < 0)
cout << "s<t" << endl;
else
cout << "s=t" << endl;
int j = strlen(s);
cout << endl;
cout << "字符串s的长度为:" << j << endl;
return 0;
}
"Microsoft Visual Studio 2010"编辑正确通过。
解决方案五:
没问题可以运行,你的头文件不是故意漏掉的吧