如何实现Java;扫描器;在C++;?

如何实现Java;扫描器;在C++;?,java,c++,visual-studio-2010,Java,C++,Visual Studio 2010,请看一下下面的java代码 import java.util.Scanner; public class Main { static int mul=1; static String convert; static char[] convertChar ; static StringBuffer buffer = new StringBuffer(""); public static void main(String[]args) {

请看一下下面的java代码

import java.util.Scanner;

public class Main
{
    static int mul=1;
    static String  convert;
    static  char[] convertChar ;
    static StringBuffer buffer = new StringBuffer("");

    public static void main(String[]args)
    {

        Scanner scan = new Scanner(System.in);

        int number=0;
        int loopValue = scan.nextInt();
       //System.out.println("print: "+loopValue);

        for(int i=0;i<loopValue;i++)
        {
            number = scan.nextInt();
           // System.out.println("print: "+number);

            for(int a=1;a<=number/2;a++)
            {
                if(number%a==0)
                {
                    //System.out.println(a);
                    mul = mul*a;
                    //System.out.println(mul);
                }
            }

           convert  = String.valueOf(mul);
           convertChar = convert.toCharArray();

           if(convertChar.length>4)
            {
               /*System.out.print(convertChar[convertChar.length-4]);
               System.out.print(convertChar[convertChar.length-3]);
               System.out.print(convertChar[convertChar.length-2]);
               System.out.print(convertChar[convertChar.length-1]);
               System.out.println();*/

               buffer.append(convertChar[convertChar.length-4]);
               buffer.append(convertChar[convertChar.length-3]);
               buffer.append(convertChar[convertChar.length-2]);
               buffer.append(convertChar[convertChar.length-1]);

                System.out.println(buffer);

            }
            else
            {
                System.out.println(mul);
            }

            //System.out.println(mul);
            mul = 1;
        }

    }
}
C++中的P>所有输入都将由测试引擎插入一个单一的输入,如下所示

62478903456


如何使用C++实现java“扫描器”?有一个头文件吗?请帮忙

您似乎在使用
扫描仪
从标准输入流中一次读取一个整数。使用提取运算符,
运算符>>
可以轻松完成此操作

替换此代码:

    Scanner scan = new Scanner(System.in);

    int number=0;
    int loopValue = scan.nextInt();
   //System.out.println("print: "+loopValue);

    for(int i=0;i<loopValue;i++)
    {
        number = scan.nextInt();
       // System.out.println("print: "+number);
Scanner scan=新的扫描仪(System.in);
整数=0;
int loopValue=scan.nextInt();
//System.out.println(“打印:+loopValue”);
对于(int i=0;i>loopvalue;
for(int i=0;i>编号;
在执行
>
操作后,应检查
std::cin
的值,以确保操作成功

参考文献:


如果使用
std::cin>>value;
读取值,则只有在检测到新行后才能处理整行

如果您希望在键入每个数字时对其进行处理,则可以使用以下函数:

int nextInt()
{
    std::stringstream s;
    while (true) 
    {
        int c = getch();
        if (c == EOF) break;
        putch(c); // remove if you don't want echo

        if ((c >= '0' && c <= '9') || (c == '-' && s.str().length() == 0)) 
            s << (char)c;
        else if (s.str().length() > 0)
            break;        
    }

    int value;
    s >> value;
    return value;
}
int-nextInt()
{
std::strings;
while(true)
{
int c=getch();
如果(c==EOF)中断;
putch(c);//如果不需要echo,请删除
如果((c>='0'&&c>值;
返回值;
}
好的,可能有更有效的写入方法,但它将逐个字符读取输入,直到遇到一个数字,并且当遇到除数字以外的任何数字时,将返回读取的任何数字


例如,1 2 3 4在第一次调用时返回1,在第二次调用时返回2,等等。

如果您不知道将输入多少,请像在Java中一样使用循环。还有其他一些方法,但使用几乎相同的代码仍然是可能的。您是从文件中读取此内容吗?这是文件的全部内容吗?如果是,则在循环中读取,直到结束他需要一个文件。如果是每行的话,就把这行分开。这是给你的链接
    int number=0;
    int loopvalue=0;
    std::cin >> loopvalue;

    for(int i = 0; i < loopValue; i++)
    {
        std::cin >> number;
int nextInt()
{
    std::stringstream s;
    while (true) 
    {
        int c = getch();
        if (c == EOF) break;
        putch(c); // remove if you don't want echo

        if ((c >= '0' && c <= '9') || (c == '-' && s.str().length() == 0)) 
            s << (char)c;
        else if (s.str().length() > 0)
            break;        
    }

    int value;
    s >> value;
    return value;
}