| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2965 人关注过本帖
标题:小白求助,运算结果二为什么是负数?
只看楼主 加入收藏
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1506
专家分:9241
注 册:2010-3-16
收藏
得分:0 
以下是引用mature119在2022-9-21 11:58:49的发言:

vs2019不能用这个,只有dec能用吗?


可以用,把下面内容保存到vs2019的 include\bits\stdc++.h


程序代码:

// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.>.

/** @file stdc++.h

 *  This is an implementation file for a precompiled header.

 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#if __cplusplus >= 201703L
#include <charconv>
#include <filesystem>
#endif

2022-09-21 19:57
Xovery
Rank: 2
等 级:论坛游民
帖 子:29
专家分:14
注 册:2022-10-22
收藏
得分:0 
VC2022中cont和printf都可以使用,有什么区别吗?
2022-10-22 02:05
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1506
专家分:9241
注 册:2010-3-16
收藏
得分:0 
回复 12楼 Xovery
printf是c语言的东西,c++兼容c语言的结果。
2022-10-22 08:41
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
以下是引用Xovery在2022-10-22 02:05:58的发言:

VC2022中cont和printf都可以使用,有什么区别吗?

printf 是 C语言标准库 带来的,C++只是继承了它。printf的缺点是 容易写错 + 无法扩展;
std::ostream 是 C++语言为了避开printf的缺点而设计出来的。ostream的缺点是 不直观 + 为了兼容printf而效率低下(自身效率并不低) + 有状态;
C++开始推广std::format,能避开以上所有缺点,当然实际效果如何,有待时间来检验。
2022-10-22 11:04
mochu
Rank: 2
等 级:论坛游民
帖 子:5
专家分:10
注 册:2020-10-4
收藏
得分:0 
程序代码:
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    unsigned char c1,c2,c3;
    c1='a';
    c2='z';
    c1=c1-32;
    c2=c2+32;
    c3='0'+9;
    cout<<int(c1)<<" "<<int(c2)<<" "<<int(c3)<<" "<<endl;
    return 0;
}


声明变量时加一个无符号数据类型
2022-11-24 16:32
billliu66
Rank: 1
等 级:新手上路
威 望:1
帖 子:4
专家分:4
注 册:2020-3-5
收藏
得分:0 
这样就可以了:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
    unsigned char c1, c2, c3;
    c1 = 'a';
    c2 = 'z';
    c1 = c1 - 32;
    c2 = c2 + 32;
    c3 = '0' + 9;
    cout << int(c1) << " " << int(c2) << " " << int(c3) << " " << endl;
    return 0;
}
2023-01-31 16:05
快速回复:小白求助,运算结果二为什么是负数?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051244 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved