错误," cout没有命名类型"

时间:2016-03-28 22:37:51

标签: c++

我正在使用开发C ++制作游戏,每当我尝试运行我的项目时,它都会给我这个错误说," cout没有命名类型"。我搜索了这个,但从来没有找到解决我的项目的答案。愿你们任何人帮忙。谢谢。

这是我的代码,

#include <iostream> 
#include <iostream> 
#include <stdlib.h>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <iomanip>

using namespace std;
char button = 'a';

int main(button){





    std::cout<< "                                                                               \n";
    std::cout<< "   *********           ********         *          ****     ********           \n";
    std::cout<< "       *              *                * *        *     *   *                  \n";
    std::cout<< "       *             *                *   *       *      *  *                  \n";
    std::cout<< "       *             *               *     *      *     *   *****              \n";
    std::cout<< "       *             *              *********     * ****    *                  \n";
    std::cout<< "       *             *             *         *    * *       *                  \n";
    std::cout<< "       *              *           *           *   *   *     *                  \n";
    std::cout<< "   *********           ********  *             *  *     *   ********           \n";
    std::cout<< "                                                                               \n";
    std::cin>> button;

    if (button == n)
    {

        system("CLS");
        std::cout<< "    ***                                                \n";
        std::cout<< "   * ..*     ***                                       \n";
        std::cout<< "   * u *    * ..*     ***        .                     \n";
        std::cout<< "    ***     * u *    * ..*      ***                    \n";
        std::cout<< "     *       ***     * u *     * ..*                   \n";
        std::cout<< "    ***       *       ***      * u *                   \n";
        std::cout<< "   * * *     ***      ***       ***                    \n";
        std::cout<< "   * * * *   * * *   * * *     *****   O               \n";
        std::cout<< "   *   * * *   *  * * * * ** ** *** * /|\              \n";
        std::cout<< "   *    *    *   *   *   *     *   *   /\              \n";
    }else
    {
        system("CLS");
        cout<<"Invalid key enter n.";

}



}

现在我已经修复了我的代码,感谢你,它给了我更多的错误,

30  16  C:\Users\Home\Documents\ICare.cpp   [Error] 'n' was not declared in this scope

42  15  C:\Users\Home\Documents\ICare.cpp   [Warning] unknown escape sequence: '\040'

43  15  C:\Users\Home\Documents\ICare.cpp   [Warning] unknown escape sequence: '\011'

47  3   C:\Users\Home\Documents\ICare.cpp   [Error] expected ';' before 'cout'

28      C:\Users\Home\Documents\Makefile.win    recipe for target 'ICare.o' failed

这些是我的其他错误。

1 个答案:

答案 0 :(得分:1)

你有可能忘记加入iostream吗?

#include <iostream>

这必须放在代码的顶部。

另外为了让cout在没有std ::的情况下工作,你必须使用命名空间:

using namespace std;

您无法在函数外部编写代码。您至少需要一个入口点:

//includes and namespaced go here

int main()
{
    //enter your code here
}

我强烈建议您完成basic tutorials

您更新的代码有一些错误:

system("CLS")

你忘记了“;”最后

if (button == n)

你没有名为“n”的变量。你可能想写:

    if (button == 'n')

同样在第41和42行,你的字符串中有“\”。这些角色具有特殊意义。在他们之前写下另一个“\”来修复这些错误。

错误在于:

int main(button){

应该是

int main(){

好的,我修复了你的代码:

#include <iostream> 
#include <stdlib.h>

using namespace std;
char button = 'a';

int main() {
    cout << "                                                                               \n";
    cout << "   *********           ********         *          ****     ********           \n";
    cout << "       *              *                * *        *     *   *                  \n";
    cout << "       *             *                *   *       *      *  *                  \n";
    cout << "       *             *               *     *      *     *   *****              \n";
    cout << "       *             *              *********     * ****    *                  \n";
    cout << "       *             *             *         *    * *       *                  \n";
    cout << "       *              *           *           *   *   *     *                  \n";
    cout << "   *********           ********  *             *  *     *   ********           \n";
    cout << "                                                                               \n";
    cin >> button;

    if (button == 'n')
    {
        system("CLS");
        cout << "    ***                                                \n";
        cout << "   * ..*     ***                                       \n";
        cout << "   * u *    * ..*     ***        .                     \n";
        cout << "    ***     * u *    * ..*      ***                    \n";
        cout << "     *       ***     * u *     * ..*                   \n";
        cout << "    ***       *       ***      * u *                   \n";
        cout << "   * * *     ***      ***       ***                    \n";
        cout << "   * * * *   * * *   * * *     *****   O               \n";
        cout << "   *   * * *   *  * * * * ** ** *** * /|\\              \n";
        cout << "   *    *    *   *   *   *     *   *   /\\              \n";
    }
    else
    {
        system("CLS");
        cout << "Invalid key enter n.";
    }
}