How do you get a file in C++?

后端 未结 4 1885
既然无缘
既然无缘 2021-01-22 03:53

So the teacher has posed this assignment:

You have been hired by the United Network Command for Law Enforcement, and you have been given files containing null cyphers yo

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 03:56

    Although your queston has been answered, two little tips: 1) Instead of counting x and y to see if you are on an odd or even character you can do the following:

    int count=0;
    while(!infile.eof())
    {       
        infile.get(letter);
        count++;
        if(count%2==0)
        {
            cout<

    % essentially means 'remainder when divided by,' so 11%3 is two. in the above it gives odd or even.

    2) Assuming you only need to run it on windows:

    system("pause");
    

    will make the window stay open when its finished running so you don't need the last getchar() call (you may have to #include for that to work).

提交回复
热议问题