cmd行到int控制台c++的转换

conversion for cmd line to int console c++

本文关键字:转换 c++ 控制台 行到 int cmd      更新时间:2023-10-16

我正在尝试使用C++将cmd行输入转换为整数。编译器告诉我它不能识别我的字符串?有人能照亮吗?

#include "stdafx.h"
#include <windows.h>
#include <string>
#pragma hdrstop
using namespace System;
int main()
{
    Console::WriteLine("Enter a num");
    string g = Console::ReadLine();
    int gi = Int32::Parse(g);
    Console::WriteLine(gi);
    Console::ReadLine();
    Console::ReadLine();
}

使用String^和Int32^托管类。如果你有Intelisense,它应该会帮助你

#包括"stdafx.h"使用命名空间System;int main(数组^args){控制台::WriteLine(L"输入数字:");String^inputStr=控制台::ReadLine();Int32^number=Int32::分析(inputStr);控制台::WriteLine(数字);控制台::ReadLine();返回0;}