Closed. This question is
not reproducible or was caused by typos。它当前不接受答案。
想改善这个问题吗?更新问题,以便将其作为
on-topic用于堆栈溢出。
3年前关闭。
Improve this question
所以我做了这个工作,当我意识到我忘了发表评论时,正准备把它放到我的gitub上,所以我回去做了,我想我做错了,因为现在我遇到了错误,我不知道该怎么做摆脱。
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class ENVIROMENT //Defines a class.
{
public:
string OS; //Difines a string.
{
if (char const* USER = std::getenv("USER")) //Checks for user name on a Unix-like system.
{
OS = "Unix"; //If true (succeded), assigns "Unix" to the variable "SYS".
}
else if(char const* USER = std::getenv("USERNAME")) //If last check was false (failed), checks for the username on Windows.
{
OS = "Windows"; //If true (succeded), assigns "Windows" to the variable "SYS".
}
else
{
OS << "Your system is not supported!"; //If both returned false (failed), assignes a "System not supported" message to SYS.
}
cout << OS << endl; //Tells the user what system they have or that it is not supported (meaning it doesn't know what OS it is).
return OS; //Returns OS to the string "OS".
}
};
int main()
{
ENVIROMENT CHECK; //Calls the class "ENVIROMENT", refers to it as "CHECK".
CHECK.OS(); //Calls the function (string) "OS" from the class "ENVIROMENT".
return 0; //Returns a value of 0 if int "main" executed successfuly.
}
错误:
ERROR: 10:11 Expected member name or ';' after declaration specifiers.
和
ERROR: 31:4 Type string does not provide a call operator.
我的问题是:这些错误是什么意思?我知道我一定缺少一些基本的东西。
编辑:应该基于用户名系统变量来检测正在运行的操作系统。在unix之类的系统上返回“Unix”,在Windows上返回“Windows”。它纯粹是教育性的,并不意味着要单独使用,但是可以在更完整的程序中使用。