Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在c++;_C++_Console_Cout - Fatal编程技术网

C++ 如何在c++;

C++ 如何在c++;,c++,console,cout,C++,Console,Cout,我试图在C++控制台应用程序中打印控制台。 void Divisibility::print(int number, bool divisible) { if(divisible == true) { cout << number << " is divisible by" << divisibleBy << endl; } else { cout << divis

我试图在C++控制台应用程序中打印控制台。

void Divisibility::print(int number, bool divisible)
{
    if(divisible == true)
    {
        cout << number << " is divisible by" << divisibleBy << endl;
    }
    else
    {
        cout << divisiblyBy << endl;
    }
}
void Divisibility::print(整数,bool可整除)
{
if(可除==真)
{

cout是的,可以在控制台上打印字符串

#include "stdafx.h"
#include <string>
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    string strMytestString("hello world");
    cout << strMytestString;
    return 0;
}
#包括“stdafx.h”
#包括
#包括
使用名称空间std;
int _tmain(int argc,_TCHAR*argv[]
{
字符串strMytestString(“hello world”);

cout您只需添加:

#include <string>
using namespace std;
#包括
使用名称空间std;
在顶端。 (顺便说一句,我知道这是2013年发布的,但我只是想回答)

“Visual Studio不支持std::cout作为非控制台应用程序的调试工具”
-从到“如何在非控制台应用程序中查看cout输出?”


这意味着如果您使用它,Visual Studio在“输出”窗口中什么也不显示(在我的例子中是VS2008)

什么不起作用?您是如何调用此代码的?您看到了什么错误?帮助我们帮助您。您所做的只是发布一段独立的代码(独立地)语法上似乎有效。您的目标是哪个操作系统?请注意,全局变量(如
divisibleBy
)不好;您应该将其作为常量引用参数传递给函数。总的来说,这是打印到
cout
的正确方法,并且如果附加了
cout
(转到)控制台,它应该是正确的。如果您从GUI IDE运行此操作,它会创建一个新窗口,然后消失,这实际上不是程序的直接问题,而是编程环境的问题。您可能希望字符串文本中的
by
后面有一个空格。请确保您没有忘记程序顶部的“using namespace std”。尝试将所有“cout”替换为“std:cout”以解决此问题。感谢您添加此注释,许多人发布的代码不完整,无法工作,因此对于初学者来说是无用的,因为缺少1或2行“include”、“using”等。