gpt4 book ai didi

c++ - 直接从命令行使用 C++ 命令

转载 作者:太空狗 更新时间:2023-10-29 20:04:20 27 4
gpt4 key购买 nike

我想问问有什么方法可以简单地使用'std::cout << "Hello world";'直接从命令行。
就像你安装了 python 一样,

$python
print 'Hello world'
Hello world

可以通过任何方式为 C++ 完成类似的事情吗?

最佳答案

cling这是一个交互式 C++ shell。我没有使用过它,但它可能符合您的需求。

这里有一些更广泛的回应:我花了一些时间来构建 Cling,主要是因为我没有完全地遵循说明并设置源代码树以包含它应该有的东西包括。以下是我用来构建和安装 cling 的步骤(构建发布版本对我不起作用):

svn co -r 191429 http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co -r 191429 http://llvm.org/svn/llvm-project/cfe/trunk clang
git clone http://root.cern.ch/git/cling.git
cd ..
cat tools/cling/patches/*.diff | patch -p0
./configure --enable-targets=host --prefix=/opt/cling
mk -j8
sudo - make install

在此之后,我得到了一个 C++ shell。当然,我的第一次交互并不完全成功,因为吸附页面说它包含一些标题。我原以为它肯定会包括 <iostream>但事实并非如此。不过,这是一个有效的简单交互:

$ /opt/cling/bin/cling 

****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ #include <iostream>
[cling]$ std::cout << "hello, world\n";
hello, world
[cling]$ #include <iterator>
[cling]$ std::copy(s.begin(), s.end(), std::ostream_iterator<char>(std::cout));
hello, world
[cling]$ .q

关于c++ - 直接从命令行使用 C++ 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20606614/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com