小编Kil*_*ing的帖子

功能没有返回我想要的值

我希望能够获取用户输入并为给定的字母赋值.我想我已经把那部分搞定了,现在问题就是返回价值.

#include <iostream>
#include <string>
using namespace std;

int ch2n(string word);

int main()
{
     string inputWord;

     cout << "Type Word: ";
     cin >> inputWord;
     cout << ch2n(inputWord);
}

int ch2n(string word)
{
    int total = 0;
    for(int i = 0;i != word.size(); i++)
    {
        if(word.find(i) == 'a' || word.find(i) == 'A')
        {
            total += 1;
        }
    }
    return total;
}
Run Code Online (Sandbox Code Playgroud)

当我将总数声明为0时,返回值始终为0,但是当我不声明它时,我得到的返回值为229 ....等随机数.

c++

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

如果最小化,如何恢复 winapi 窗口?

我尝试了许多功能,例如ShowWindow&IsWindowVisible至少尝试在窗口最小化时给出结果,更不用说恢复它了。无论窗口是否最小化,这些函数都会不断返回 false。我一直在使用也试图GetWindowPlacementSetWindowPlacement没有成功。我HWND发现 ChromeFindWindow(TEXT("Chrome_WidgetWin_1"), NULL);成功了,但我想测试/恢复窗口是否最小化并且过去 10 个小时没有任何显示。

c++ windows winapi

3
推荐指数
1
解决办法
3886
查看次数

如何打开一个txt文件而不删除以前的内容

所以我希望能够在控制台关闭后打开文件并能够继续添加到文件中。

int main(){
    string inputWord;
    ofstream theFile("Info.txt");
    cout << "Type Word or Sentence: ";

    while(getline(cin,inputWord)){
        cout << "Type Word or Sentence: ";
        theFile << "Word or Sentence: " << inputWord;
        theFile << "(Regular Value): " << ch2n(inputWord) << endl;
        theFile << "(Other Value): " << char2num(inputWord) << endl;
        theFile << "(Sum): " << ch2n(inputWord) + char2num(inputWord) << endl;
        theFile << "(Difference): " << ch2n(inputWord) - char2num(inputWord) << endl;
        theFile << "(Total): " << ch2n(inputWord) + (ch2n(inputWord)+char2num(inputWord)) + (ch2n(inputWord)-char2num(inputWord)) + char2num(inputWord) …
Run Code Online (Sandbox Code Playgroud)

c++ fstream

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

如何使用WinAPI更改标题栏图标

我使用Windows API制作了一个应用程序,并使用资源文件夹将图标更改为我制作的自定义图标。现在程序正在使用我在桌面上的图标,但是标题栏中有默认图标,准确地说就是这个图标。默认图标

现在我应该如何将其更改为自定义图标?我正在使用MSVC ++

WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;


hwnd = CreateWindow(szAppName,
    TEXT("Random"),
    WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    300,
    120,
    NULL,
    NULL,
    hInstance,
    NULL);
Run Code Online (Sandbox Code Playgroud)

c c++ windows winapi visual-studio

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

循环内部开关变得无限

当程序进入第二个循环时,即使我将第二个循环的值设置为false,它也会变为无限.问题出在哪里?第一个while循环我从来没有遇到任何问题退出,但第二个...我只是看不到在哪里或为什么.

int RareData::assignRareType()
{

    int switchType;
    std::cin >> switchType;
    bool valid = true;
    bool valid2 = true;

    while (valid)
    {
        switch (switchType)
        {

        case 0:
            std::cout << "1 - Character Change\n2 - Account Change\n3 - Both\n";
            int switchData;
            std::cin >> switchData;
            valid2 = true;

            while (valid2)
            {
                switch (switchData)
                {
                case 1:
                    valid2 = false;
                    std::cin.clear();
                    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
                    assignCharacter();
                    break;
                case 2:
                    valid2 = false;
                    std::cin.clear();
                        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
                    assignAccount();
                    break;
                case 3:
                    valid2 = false;
                    std::cin.clear();
                    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
                    assignAccount();
                    assignCharacter(); …
Run Code Online (Sandbox Code Playgroud)

c++ while-loop switch-statement

0
推荐指数
1
解决办法
66
查看次数

fstream没有创建文本文件

似乎当我尝试运行这个代码源而不是创建Attempt1.txt,或Attempt2.txt或Attempt3.txt时,它只是创建一个名为Attempt的文件.

    string str;
    int num_attempts_x_million = 1;

    str = "Attempt";
    str += num_attempts_x_million;
    str += ".txt";
    textfile.open(str); 
    textfile << password << endl;
    textfile.close();
Run Code Online (Sandbox Code Playgroud)

c++ string fstream

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