简体   繁体   中英

conversion for cmd line to int console c++

I am trying to convert cmd line input into an integer using C++. The compiler tells me it doesn't recognize my string? Can someone shed some light?

#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();
}

Use String^ and Int32^ - managed classes. If you have Intelisense it should help you

#include "stdafx.h"

using namespace System;

int main(array ^args)
{
    Console::WriteLine(L"Enter a number:");
    String^ inputStr = Console::ReadLine();
    Int32^ number = Int32::Parse(inputStr);

    Console::WriteLine(number);

    Console::ReadLine();
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM