小编Crj*_*rju的帖子

错误:未在此范围内声明'myfile'

好的,我正在尝试将加密文本写入文件.

由于某种原因,我得到一个未在此范围内声明编译错误.

这是我的encryption.cpp文件:

#include <iostream>
#include <fstream>
#include <string>

class encrypt{
    public:
        static void cryptText(std::string newpass)
        {
            int x = newpass.size();

            int output[x -1];

            for(int i = 0; i <= x -1; i++)
            {
                output[i] = (int)newpass[i];
                std::cout << char(output[i] + x);
                //Here I am trying to write output onto the file. For some reason, though,
                //I get the error.
                myfile.open ("passwords.thaddeus");
                myfile << output << std::endl;
                myfile.close();

            }

            std::cout << std::endl;

        }

};
Run Code Online (Sandbox Code Playgroud)

我查看了带文件的输入/输出的cplusplus.com文档.我将他们的示例程序复制到Code :: Blocks中,它运行得很好.但是当我尝试它时,我得到了错误.这很奇怪,因为我包括在内.

c++ file input

2
推荐指数
2
解决办法
2万
查看次数

C++ - 寻找"帮助"

好吧,所以我实际上已经用C++进行了一段时间的编程,但是我现在对可能非常明显的事情感到难过.我决定写一个基本的计算器以获得乐趣.加,减,乘,除,整数.正如你在下面看到的,我有一个名为choice的int变量,寻找1,2,3或4.一旦选择,它将调用相应的函数.但是,我决定我希望能够随时输入"帮助"来表示帮助.我怎样才能做到这一点?我知道我可以简单地选择一个字符串,但我觉得这只会在问题上设置一个绑定(对未来的问题没有帮助).我想随时抓住"帮助".但是,使用另一个if()语句来捕获"帮助"

请帮助我,我相信这很简单,但由于某种原因我无法弄清楚!

#include <iostream>

int firstnum;
int secondnum;

int multiplication(){
    std::cout << "Multiplication chosen. Please enter first number." << std::endl;
    std::cin >> firstnum;
    std::cout << "Please enter second number." << endl;
    std::cin >> secondnum;
    std::cout << "Your answer is: " << firstnum * secondnum << "." << std::endl;
}

int division(){
    std::cout << "Division chosen. Please enter first number." << std::endl;
    std::cin >> firstnum;
    std::cout << "Please enter second number." << std::endl;
    std::cin >> secondnum;
    std::cout << "Your …
Run Code Online (Sandbox Code Playgroud)

c++ function

-1
推荐指数
1
解决办法
115
查看次数

标签 统计

c++ ×2

file ×1

function ×1

input ×1