c++ - Int32 未在此范围内声明

标签 c++

我有以下代码:

//Comp454 program 2
#include <iostream>
#include <string>
#include <fstream> // file I/O support
#include <cstdlib> // support for exit()
const int SIZE = 60;

int main()
{
 using namespace std;
 string states;
 int numStates = 0, i = 0, stateVar = 0;
 string line;
 char filename[SIZE];
 ifstream inFSM, inString;

 //Open FSM definition
 cout << "Enter name of FSM definition: ";
 cin.getline(filename, SIZE);
 inFSM.open(filename); //Associate inFile with a file
 if (!inFSM.is_open()) // failed to open file
 {
 cout << "Could not open the file " << filename << endl;
 cout << "Program terminating.\n";
 exit(EXIT_FAILURE);
 }

 //Process FSM definition line by line until EOF
 getline(inFSM, states);
 numStates = Int32.TryParse(states);

 //Check for num of states
 if(numStates > 10)
 {
  cout << "There can be no more than 10 states in the FSM definition, exiting now." << endl;
  return 0;
 }

 while (!inFSM.eof()) // while input good and not at EOF
 {
  getline(inFSM, line);
  cout << line << endl;
 }

 return 0;
}

我正在尝试使用 Int32.TryParse() 将字符串转换为整数,但在编译时出现错误,指出未在此范围内声明 Int32。不确定为什么会出现这种情况,我是否缺少命名空间声明??感谢任何帮助,谢谢

更新: 感谢所有回复,正如我发表的评论中所述,我并没有尝试使用 C++/CLI,如何将字符串类(从字符串类声明)转换为整数?

最佳答案

尝试使用 atoi()反而。 States 是一个 std::string 所以你需要说:

numStates = atoi( states.c_str() );

关于c++ - Int32 未在此范围内声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1787599/

相关文章:

c++ - 带有 "endl"的模板函数的 VS2015 编译错误

c++ - 无法在 Qt 中读取 utf-8 文件

c++ - 我应该为游戏中的过场动画使用哪种视频解码器?

c++ - 正则表达式:查找标签列表作为行尾

c++ - 链表不打印值?我究竟做错了什么

c++ - 如何为元素( vector 和整数)也是 unique_ptr 的对创建 unique_ptr?

c++ - 为什么我们不能用抽象类创建容器?

c++ - C++将指针传递给对象的指针,无法访问成员

c++ - 有人可以解释以下语法及其功能吗?

C# 相当于 imbue 和 numpunct