我们定义一个string 变量str ,然后通过str.length()可以获得该字符串变量的长度:

#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
cout<<str.length()<<endl;
return 0;
}

string变量相当于是一个变长的字符数组,随着输入的字符串长度的长度的变化而变化。

既然是字符数组,就必然是可以以字符数组的形式进行输出了。

#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
cout<<str.length()<<endl;
for(int i=0;i<str.length();i++)
{
cout<<str[i]<<" ";
}
return 0;
}

将一个string字符串变量分解为字符输出的更多相关文章

  1. [LeetCode] First Unique Character in a String 字符串第一个不同字符

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  2. [CareerCup] 1.1 Unique Characters of a String 字符串中不同的字符

    1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...

  3. Java String字符串/==和equals区别,str。toCharAt(),getBytes,indexOf过滤存在字符,trim()/String与StringBuffer多线程安全/StringBuilder单线程—— 14.0

    课程概要 String 字符串 String字符串常用方法 StringBuffer StringBuilder String字符串: 1.实例化String对象 直接赋值  String str=& ...

  4. C++学习37 string字符串的访问和拼接

    访问字符串中的字符 string 字符串也可以像字符串数组一样按照下标来访问其中的每一个字符.string 字符串的起始下标仍是从 0 开始.请看下面的代码: #include <iostrea ...

  5. 关于String字符串反转

    这是网上看到的一篇java面试题中的问题: 问题是: 如何将一个String字符串反转. String str = "1234567"; int length = str.leng ...

  6. [CareerCup] 1.3 Permutation String 字符串的排列

    1.3 Given two strings, write a method to decide if one is a permutation of the other. 这道题给定我们两个字符串,让 ...

  7. 03-Java String字符串详解

    1.Java字符串String A.实例化String字符串:直接赋值(更合理一些,使用较多).使用关键字new. B.String内容的比较 // TODO Auto-generated metho ...

  8. Delphi的字符(Char),字符串(String),字符串指针(PChar),字符数组arrayofchar(来自http://delphi.cjcsoft.net/论坛)

    Delphi有三种类型的字符: AnsiChar这是标准的1字节的ANSI字符,程序员都对它比较熟悉. WideChar这是2字节的Unicode字符. Char在目前相当于AnsiChar,但在De ...

  9. 【转】C语言中,为什么字符串可以赋值给字符指针变量

    本文是通过几篇转帖的文章整理而成的,内容稍有修改: 一. C语言中,为什么字符串可以赋值给字符指针变量 char *p,a='5';p=&a;                     //显然 ...

随机推荐

  1. linux下安装Java se和Eclipse

    首先要去下载好JDK,Java SE 8的官方网址是http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...

  2. mysql 视图、触发器、事物、存储过程、函数

    一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  3. Oracle 11g 客户端连接 oracle 10g 服务端,乱码问题

    从网上搜索资料基本确定:字符集错误 Pl/sql 连接到oracle 数据库   “select userenv('language') from dual” 找到服务端的对应的字符集,拷贝之: 到本 ...

  4. Centos7 安装 MongoDB4.0

    目录 安装包下载 MongoDB安装 启动数据库 补充 小结 诚邀访问我的个人博客:我在马路边 更好的阅读体验点击查看原文:Centos7安装MongoDB4.0 原创博客,转载请注明出处 @ 由于项 ...

  5. git常用命令备忘录

    返回未修改状态 [git checkout . --没有的提交的,都返回到原来的状态  git clean -xdf 删除文件和目录] git checkout . && git cl ...

  6. Excel中函数row和column的特殊应用

    版本:2016,数据来源:我要自学网-曾贤志老师 row在英文中是行,排的意思,在Excel中的作用是返回所引用的行号.​   column在英文中是列,总队的意思,其作用是返回所引用的列号.   假 ...

  7. Java实现Queue类

    Java实现Queue类 import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Sc ...

  8. AFN 请求数据https

    第一步: 导入afn库 第二步: 在pch中添加 #import <SystemConfiguration/SystemConfiguration.h> #import <Mobil ...

  9. Java基础--单例类创建和测试

    单例模式的主要作用是保证在Java程序中,某个类只有一个实例存在.单例模式有很多好处,它能够避免实例对象的重复创建,不仅可以减少每次创建对象的时间开销,还可以节约内存空间:能够避免由于操作多个实例导致 ...

  10. 用Nmap检测漏洞

    介绍两个NSE脚本,可以检测CVE漏洞 nmap-vulners:https://github.com/vulnersCom/nmap-vulners vulscan:https://github.c ...