使用 C++/CLI 示例时出现编译时错误

问题描述 投票:0回答:2

我正在尝试从文件中读取一个作为“数字”的字符串,并将其转换回整数。以下是我的代码,是 C++/CLI

int InformationReader::getThreshold()
{
    StreamReader ^reader = gcnew StreamReader("threshold.dat");
    System::String ^thresholdStr = reader->ReadLine();

    Int32 thresholdNum;

    boolean a = Int32::TryParse(thresholdStr,thresholdNum);

    return 0;

}

但是,一旦执行此代码,我就会收到以下错误

1>InformationReader.cpp(29): error C2065: 'Int32' : undeclared identifier
1>InformationReader.cpp(29): error C2146: syntax error : missing ';' before identifier 'thresholdNum'
1>InformationReader.cpp(29): error C2065: 'thresholdNum' : undeclared identifier
1>InformationReader.cpp(31): error C2065: 'boolean' : undeclared identifier
1>InformationReader.cpp(31): error C2146: syntax error : missing ';' before identifier 'a'
1>InformationReader.cpp(31): error C2065: 'a' : undeclared identifier
1>InformationReader.cpp(31): error C2653: 'Int32' : is not a class or namespace name
1>InformationReader.cpp(31): error C2065: 'thresholdNum' : undeclared identifier
1>InformationReader.cpp(31): error C3861: 'TryParse': identifier not found

现在这对我来说很陌生,因为我经历了很多问题和答案,并且在所有这些问题和答案中,他们都遵循了与我使用的相似的方法,但我遇到了错误。为什么是这样?

.net visual-studio-2010 visual-c++ c++-cli
2个回答
2
投票

修复你看到的第一个编译错误:你需要在

System::
前面加一个
Int32 thresholdNum;


0
投票

我正在处理一个 C++/CLI 项目,突然出现大量编译错误——来自文件“cmath”(主要是)、“exception”、“ctime”,但这些文件甚至没有包含在项目中......

最后发现,我只是少了一个

};
。然后一切都修好了。

奇怪的经历。

© www.soinside.com 2019 - 2024. All rights reserved.