有什么方法可以从不同功能的变量中检索值? C ++

例如,我有一个将二进制数转换为十进制的函数,以及另一个将十进制数转换为二进制数的函数。然后,我有另一个函数来检查二进制和十进制数字是否匹配(都表示相同的数字)。这三个操作必须是单独的功能。我需要检查函数中的二进制函数值和十进制函数的值来检查它们。

我可以使用返回值吗?我不想使用全局变量。抱歉,这是一个愚蠢的问题,因为我是函数新手。

hijbly 回答:有什么方法可以从不同功能的变量中检索值? C ++

您可以使用int double之类的函数并返回输出。它可以用作普通变量,但可以在其中进行计算。

[root@localhost site-packages] pyenv virtualenv 2.7.12 nanovar

New python executable in /root/.pyenv/versions/2.7.12/envs/nanovar/bin/python2.7
Also creating executable in /root/.pyenv/versions/2.7.12/envs/nanovar/bin/python
Installing setuptools,pip,wheel...

  Complete output from command /root/.pyenv/version...anovar/bin/python2.7 - setuptools pip wheel:
  DEPRECATION: Python 2.7 will reach the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Created temporary directory: /tmp/pip-ephem-wheel-cache-gFPfrS
Created temporary directory: /tmp/pip-req-tracker-UI5fK2
Created requirements tracker '/tmp/pip-req-tracker-UI5fK2'
Created temporary directory: /tmp/pip-install-Ck6zPW
Looking in links: /root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support
Collecting setuptools
  1 location(s) to search for versions of setuptools:
  * https://pypi.org/simple/setuptools/
  Skipping link /root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support (from -f); not a file
  Getting page https://pypi.org/simple/setuptools/
  Looking up "https://pypi.org/simple/setuptools/" in the cache
  Request header has "max_age" as 0,cache bypassed
Cleaning up...
Removed build tracker '/tmp/pip-req-tracker-UI5fK2'
ERROR: Exception:
Traceback (most recent call last):
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py",line 178,in main
    status = self.run(options,args)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/commands/install.py",line 352,in run
    resolver.resolve(requirement_set)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/resolve.py",line 131,in resolve
    self._resolve_one(requirement_set,req)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/resolve.py",line 294,in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/resolve.py",line 242,in _get_abstract_dist_for
    self.require_hashes
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/operations/prepare.py",line 282,in prepare_linked_requirement
    req.populate_link(finder,upgrade_allowed,require_hashes)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/req/req_install.py",line 198,in populate_link
    self.link = finder.find_requirement(self,upgrade)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py",line 766,in find_requirement
    candidates = self.find_candidates(req.name,req.specifier)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py",line 752,in find_candidates
    self.find_all_candidates(project_name),File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py",line 716,in find_all_candidates
    for page in self._get_pages(url_locations,project_name):
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py",line 846,in _get_pages
    page = _get_html_page(location,session=self.session)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py",line 231,in _get_html_page
    resp = _get_html_response(url,session=session)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py",line 179,in _get_html_response
    "Cache-Control": "max-age=0",File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py",line 546,in get
    return self.request('GET',url,**kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/download.py",line 439,in request
    return super(PipSession,self).request(method,*args,**kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py",line 533,in request
    resp = self.send(prep,**send_kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py",line 646,in send
    r = adapter.send(request,**kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/adapter.py",line 51,in send
    request.headers.update(self.controller.conditional_headers(request))
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/controller.py",line 233,in conditional_headers
    resp = self.serializer.loads(request,self.cache.get(cache_url))
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/serialize.py",line 97,in loads
    return getattr(self,"_loads_v{}".format(ver))(request,data)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/serialize.py",line 161,in _loads_v2
    cached["response"]["body"] = _b64_decode_bytes(cached["response"]["body"])
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/serialize.py",line 13,in _b64_decode_bytes
    return base64.b64decode(b.encode("ascii"))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-57970: ordinal not in range(128)
----------------------------------------
...Installing setuptools,wheel...done.
Traceback (most recent call last):
  File "/root/.pyenv/versions/2.7.12/bin/virtualenv",line 11,in <module>
    sys.exit(main())
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py",line 870,in main
    symlink=options.symlink,File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py",line 1173,in create_environment
    install_wheel(to_install,py_executable,search_dirs,download=download)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py",line 1019,in install_wheel
    _install_wheel_with_search_dir(download,project_names,search_dirs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py",line 1110,in _install_wheel_with_search_dir
    call_subprocess(cmd,show_stdout=False,extra_env=env,stdin=script)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py",line 963,in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc,proc.returncode))
OSError: Command /root/.pyenv/version...anovar/bin/python2.7 - setuptools pip wheel failed with error code 2
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: setuptools,pip
Successfully installed pip-8.1.1 setuptools-20.10.1
本文链接:https://www.f2er.com/3130627.html

大家都在问