-1

私の関数「CSS()」がこのコードで機能しないのはなぜですか。エラーは次のとおりです。

C:\Users\KEstudio\Desktop\Programming\Learning C++ resources\projects\homework     saver\main.cpp||In function 'int main()':|
C:\Users\KEstudio\Desktop\Programming\Learning C++ resources\projects\homework    saver\main.cpp|20|error: 'CLSS' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

これが私のコードです:

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

void ClSS()
{
    system("CLS");
}
const char* CTS(string);

int main()
{
    A:
    string HWS, HW;//We will be saving our input in this
    cout << "Please enter the homework subject:" << endl;
    getline(cin, HWS);
    CLSS();

    cout << "Please enter the homework:" << endl;
    getline(cin, HW);
    CLSS();

    ofstream myfile;
    myfile.open(CTS(HWS+".txt"));
    myfile << HW;
    myfile.close();

    cout << "You have saved the information to a file! :D" << endl;

    string SEL;
    bool ASEL=false;
    cout << "Do you wan't to add another entry? yes or no" << endl;
    getline(cin, SEL);
    system("CLS");
    if(SEL=="yes" || SEL=="Yes" || SEL=="YES" || SEL=="Y" || SEL=="y")
        ASEL=true;
    else
        ASEL=false;
    if(ASEL==true)
        goto A;
    return 0;
}

const char* CTS(string strng)
{
    const char* FON;
    FON=strng.c_str();
    return FON;
}

関数が宣言されていることがわかります。C++ にはこのようなバグがないことはわかっているので、何か間違ったことをしています。これが C++ のバグであるはずはありません。 m が間違っています (うまくいけば、完全にばかげているわけではないので、あまりばかげているようには見えませんが、このようなコードでは、おそらく単純な解決策になるでしょう)

わかりました CLSS はメイン関数の上で宣言されていることがわかります。関数は、メイン関数内で機能するためにメイン関数内で宣言する必要はありません。

4

1 に答える 1

3

を宣言しClSS()ましたが、呼び出していますCLSS()。後者はどこにも宣言されていません。

于 2013-02-23T14:28:34.087 に答える