나는 다음과 같은 코드가 있습니다INT32은이 범위에서 선언하지
//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, 문자열 클래스에서 선언 된 문자열을 변환하는 방법을 사용하려고하지 않아요 , 정수로?
내가 오히려'strtol' 조언을 것입니다 : 당신이 말할 필요가 있도록 미국은 표준 : : 문자열 숫자가 올바르지 않은 경우 또는 숫자가 아닌 문자열을 파싱하지 못한 경우 - 두 경우 모두'atoi '에서'0'을 얻음). –