c ++查找字符串_C ++机械手| 查找输出程序| 套装2

news/2024/7/20 1:44:25 标签: 字符串, c++, python, 正则表达式, 小程序

c ++查找字符串

Program 1:

程序1:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    cout << 3.123456789 << endl;
    cout << setprecision(3) << 3.123456789 << endl;

    return 0;
}

Output:

输出:

3.12346
3.12

Explanation:

说明:

Here, we used setprecision() manipulator then it sets the precision value. Here we used precision value 3, and then we print "3.12" instead of "3.123456789".

在这里,我们使用了setprecision()操纵器,然后它设置了精度值。 在这里,我们使用精度值3 ,然后打印“ 3.12”而不是“ 3.123456789”

Program 2:

程式2:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    unsigned char str[] = "World";
    cout << "Hello" << setw(7) << str;
    return 0;
}

Output:

输出:

Hello  World

Explanation:

说明:

Here, we used setw() manipulator which is used to set the width of the string. If the specified string has less character than setw(), then it will add spaces at the left side of the string.

在这里,我们使用了setw()操纵器,该操纵器用于设置字符串的宽度。 如果指定的字符串的字符少于setw() ,则它将在字符串的左侧添加空格。

In our example, size of the str is 5 and we used 7 in setw() then it will add 2 spaces on the left side.

在我们的示例中, str的大小为5,我们在setw()中使用了7,然后它将在左侧添加2个空格。

Program 3:

程式3:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    unsigned char str[] = "World";
    cout << "Hello" << setw(7) << str << str;
    return 0;
}

Output:

输出:

Hello  WorldWorld

Explanation:

说明:

Here, we used setw() manipulator which is used to set the width of the string. If the specified string has less character than setw(), then it will add spaces at the left side of the string.

在这里,我们使用了setw()操纵器,该操纵器用于设置字符串的宽度。 如果指定的字符串的字符少于setw() ,则它将在字符串的左侧添加空格。

Here, width is set only for 1st str in the cout statement. The 2nd str will be printed as it is. Then the final output "Hello  WorldWorld" will be printed on the console screen.

在这里,宽度仅在COUT声明1 海峡设置。 2nd str将按原样打印。 然后,最终输出“ Hello WorldWorld”将被打印在控制台屏幕上。

Program 4:

计划4:

#include <iostream>
#include <iomanip>
#include <ios>
using namespace std;

int main()
{
    cout << setw(15) << setfill('*') << "includehelp" << setw(20) << setfill('#') << "tutorials" << endl;
    return 0;
}

Output:

输出:

****includehelp###########tutorials

Explanation:

说明:

Here, we used setw() and setfill() manipulators.

在这里,我们使用了setw()setfill()操纵器。

  • setw() : This is used to set the width of string that will be printed on the console screen.

    setw() :用于设置将在控制台屏幕上打印的字符串的宽度。

  • setfill() : This is used to fill the specified character.

    setfill() :用于填充指定的字符。

We set width 15 for string "includehelp" so 4 '*' are padded at the left side. And set 20 for string "tutorials" so 11 '#' is padded at the left side.

我们为字符串“ includehelp”设置了宽度15,因此在左侧填充了4个“ *” 。 并为字符串“ tutorials”设置20,以便在左侧填充11个“#”

翻译自: https://www.includehelp.com/cpp-tutorial/manipulators-find-output-programs-set-2.aspx

c ++查找字符串


http://www.niftyadmin.cn/n/1255624.html

相关文章

python日历模块_Python日历模块| calendar()方法与示例

python日历模块Python calendar.calendar()方法 (Python calendar.calendar() Method) calendar() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and returns a 3-column calendar for an entire year as a multi-line s…

ThinkPHP5.1完全开发手册.CHM离线版下载

ThinkPHP5.1完全开发手册.CHM离线版下载 ThinkPHP5.1完全开发手册离线版.CHM下载地址 百度云&#xff1a;链接: https://pan.baidu.com/s/1b4jKJN-8UyIlH5VDCCh40g 密码: ygsj 转载于:https://www.cnblogs.com/itzhoubao/p/9199558.html

stl取出字符串中的字符_如何在C ++ STL中将字符转换为字符串?

stl取出字符串中的字符将字符转换为字符串 (Converting character to string) Sometimes, It may be needed to convert a character variable to a string variable. In C, we can do this by calling the constructor of the string class. For example, a will be converted…

LeetCode:10.表达式匹配(Regular Expression Matching)

10.表达式匹配&#xff08;Regular Expression Matching&#xff09; 给定参数字符串s和匹配表达式p,实现支持 . 和 * 的表达式匹配&#xff0c;需要匹配整个字符串&#xff08;而不是其中一部分&#xff09;。 说明 字符串s可以为空&#xff0c;可以只包含小写字母a-z。匹配…

Java集合框架体系

Java中提供了很多的“集合类”&#xff1a;ArrayList&#xff0c;LinkedList&#xff0c;HashSet&#xff0c;LinkedHashSet&#xff0c;HashMap&#xff0c;LinkedHashMap等等 为什么要有这么多集合类那&#xff0c;是因为这些集合类内部都采用了不同的“存储方式”&#xff0…

insert方法 c#_清单 .Insert()方法,以C#为例

insert方法 c#C&#xff03;List <T> .Insert()方法 (C# List<T>.Insert() Method) List<T>.Insert() method is used to insert an element at specified index in the list. List <T> .Insert()方法用于在列表中的指定索引处插入元素。 Syntax: 句法…

设置session超时的三种方式

1. 在容器中设置&#xff1a;如在tomcat-5.0.28\conf\web.xml中设置 Tomcat默认session超时时间为30分钟&#xff0c;可以根据需要修改&#xff0c;负数或0为不限制session失效时间。 [html] view plaincopy<session-config> <session-timeout>30</s…

c语言指针++_C ++此指针| 查找输出程序| 套装2

c语言指针Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Test {int VAL;public:Test(int VAL){this->VAL VAL;cout << this->VAL;}};int main(){Test T;return 0;}Output: 输出&#xff1a; main.cpp: In function ‘int m…