我有一个代码: “Hello World” 的我们可以找回在cout中传递的字符串吗?
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<<"Hello World!";
getch();
return 0;
}
我可以拿回串在一些字符或字符串变量?
我有一个代码: “Hello World” 的我们可以找回在cout中传递的字符串吗?
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<<"Hello World!";
getch();
return 0;
}
我可以拿回串在一些字符或字符串变量?
没有,但你可以使用字符串流来达到这样的效果:
#include <iostream>
#include <sstream>
std::ostringstream oss;
oss << "Hello World!";
std::cout << oss.str();
现在oss.str()
仍然包含您构建的字符串。
这是一个很好的方法,但不是所需的答案,在这里你也做了一个变量,通过了“Hello World!”然后在std :: cout中使用该变量: – user3284775
@ user3284775:问题的严格答案是“否”,其余显示几乎是直接替换的次最佳解决方案。 –
为什么不把它写入变量之前写入cout? – Barmar
@Barmar如果你想要一个变量的整个输出屏幕?你不能连接每个字符串变量在一个btw我只是在探索。 – user3284775
@ user3284775无法连接每个字符串变量?当然你可以......这并不是什么有用的东西,但是没有任何东西阻止你这么做。 –