我试图在c ++控制台应用程序中打印一个字符串到控制台.
void Divisibility::print(int number, bool divisible)
{
if(divisible == true)
{
cout << number << " is divisible by" << divisibleBy << endl;
}
else
{
cout << divisiblyBy << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我有正确的包含等,这个错误,我相信只是我只是不知道如何打印到c ++控制台,我想这不是这样做的方式
编辑:抱歉忘了提到divisiblyBy是字符串
Ric*_*ich 25
是的,可以将字符串打印到控制台.
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string strMytestString("hello world");
cout << strMytestString;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
stdafx.h与解决方案无关,其他一切都是.
小智 14
您所要做的就是添加:
#include <string>
using namespace std;
Run Code Online (Sandbox Code Playgroud)
在顶部.(顺便说一下,我知道这是2013年发布但我只是想回答)
“Visual Studio 不支持 std::cout 作为非控制台应用程序的调试工具”
- 来自Marius Amado-Alves对“如何在非控制台应用程序中查看 cout 输出? ”的回答
这意味着如果您使用它,Visual Studio 在“输出”窗口中不会显示任何内容(在我的例子中是 VS2008)
| 归档时间: |
|
| 查看次数: |
129227 次 |
| 最近记录: |