【发布时间】:2020-03-04 15:00:59
【问题描述】:
当我尝试编译以下代码时,我得到了错误
strupr.cpp:在函数“int main()”中:strupr.cpp:9:10:错误:“strupr” 未在此范围内声明 cout
#include<iostream>
#include<cstring>
using namespace std;
int main(void){
cout << strupr("hello world") << endl;
}
【问题讨论】:
-
请在问题中包含代码,不要作为链接,尤其不要作为图片。
-
c-String 函数位于 cstring 标头而不是 string.h。此外,stdupr 不是标准函数,可能不包含在您的 libc 中。请改用std::transform 和std::toupper。
-
int main(void){不是有效的 C++ 代码。 -
这是
namespace而不是namesapce -
strupr将其参数转换为大写。strupr("hello world");尝试将文字字符串转换为大写;您不允许修改文字字符串,因此这不起作用。char str[] = "hello world"; strupr(str);可以,因为str不是文字,可以修改。
标签: c++