I/O流操纵器-AndingField Internal -C vsC
I/O Stream manipulator - adjustfield internal - C++ vs C
程序员在这里。我在课堂作业的一部分方面遇到了麻烦。我们的任务是将C 程序转换为C程序。
由于使用"内部"流操纵器,我很难转换一行代码。它需要在输出中看起来像这样:
+ 6443.
或- 6443.
,但我似乎无法使用C标准而不是C
实现这一目标这是我应该转换的C 中的代码:
cout << setprecision(4) << setw(13) << internal << showpoint << showpos << fourth << endl;
我已经尝试过,但是/-仍在数字旁边。
printf("%+13.0f. n", fourth);
如果整体更容易理解,这是整个程序...
#include <stdio.h>
#include <stdlib.h>
main()
{
//bool first; //Changing data type for standard C Input
int first; //This is in place of the bool
int second;
//long third; //Changing data type for standard C input
int third; //This is in place of long
float fourth;
float fifth;
//double sixth; //Changing data type for standard C input
float sixth; //This is place of double
//cout << "Enter bool, int, long, float, float, and double values: ";
printf("Enter bool, int, long, float, float, and double values: ");
//cin >> first >> second >> third >> fourth >> fifth >> sixth;
scanf("%d %d %d %f %f %f", &first, &second, &third, &fourth, &fifth, &sixth);
//cout << endl;
printf("n");
//1 - 3
printf("%d", first);
if(first > 0)
printf(" true n");
else
printf(" false n");
printf("%d %#x %#o n", second, second, second);
printf("%16d n", third);
//4
//cout << setprecision(4) << setw(13) << internal << showpoint << showpos << fourth << endl;
printf("%+13.0f. n", fourth); //Issues
//5
printf("%15.4en", fourth);
//6
//cout << left << setprecision(7) << fifth << endl;
printf("%-.7e n", fifth); //Issues
//7 - 12
printf("%17.3f n", fifth);
printf("%-d n", third);
printf("%16.2f n", fourth);
printf("%13.0f n", sixth);
printf("%14.8f n", fourth);
printf("%16.6g n", sixth);
return 0;
}
输出' '或' - 作为单独的%c参数,
printf( "%c%13dn",( (forth >=0)? '+' : '-' ), abs(forth) );
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp