将一个string字符串变量分解为字符输出
我们定义一个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字符串变量分解为字符输出的更多相关文章
- [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 ...
- [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 ...
- Java String字符串/==和equals区别,str。toCharAt(),getBytes,indexOf过滤存在字符,trim()/String与StringBuffer多线程安全/StringBuilder单线程—— 14.0
课程概要 String 字符串 String字符串常用方法 StringBuffer StringBuilder String字符串: 1.实例化String对象 直接赋值 String str=& ...
- C++学习37 string字符串的访问和拼接
访问字符串中的字符 string 字符串也可以像字符串数组一样按照下标来访问其中的每一个字符.string 字符串的起始下标仍是从 0 开始.请看下面的代码: #include <iostrea ...
- 关于String字符串反转
这是网上看到的一篇java面试题中的问题: 问题是: 如何将一个String字符串反转. String str = "1234567"; int length = str.leng ...
- [CareerCup] 1.3 Permutation String 字符串的排列
1.3 Given two strings, write a method to decide if one is a permutation of the other. 这道题给定我们两个字符串,让 ...
- 03-Java String字符串详解
1.Java字符串String A.实例化String字符串:直接赋值(更合理一些,使用较多).使用关键字new. B.String内容的比较 // TODO Auto-generated metho ...
- Delphi的字符(Char),字符串(String),字符串指针(PChar),字符数组arrayofchar(来自http://delphi.cjcsoft.net/论坛)
Delphi有三种类型的字符: AnsiChar这是标准的1字节的ANSI字符,程序员都对它比较熟悉. WideChar这是2字节的Unicode字符. Char在目前相当于AnsiChar,但在De ...
- 【转】C语言中,为什么字符串可以赋值给字符指针变量
本文是通过几篇转帖的文章整理而成的,内容稍有修改: 一. C语言中,为什么字符串可以赋值给字符指针变量 char *p,a='5';p=&a; //显然 ...
随机推荐
- ural 2013 Neither shaken nor stirred
2013. Neither shaken nor stirred Time limit: 1.0 secondMemory limit: 64 MB The ACM ICPC regional con ...
- Ceph pg分裂流程及可行性分析
转自:https://www.ustack.com/blog/ceph-pg-fenlie/ 1 pg分裂 Ceph作为一个scalable的分布式系统,集群规模会逐渐增大,为了保证数据分布的均匀性, ...
- Intellij IDEA导入Github中的MAVEN多模块项目【保持项目样式】
刚上手用IntelliJ IDEA导入github项目,我尝试了多种导入方式.因为我的有父子模块,导入后整个项目的格式就变了. 然后我多次尝试,找到了一个更好的导入方式,可以保持MAVEN项目的格式. ...
- es6基础入门变量的解构赋值
let [a, b, c] = [1, 2, 3]; let [foo, [[bar], baz]] = [1, [[2], 3]]; foo bar baz let [ , , third] = [ ...
- 简单使用location.hash的方法 ,怎么做,有什么用? 简单的js路由页面方法。
hash 属性是一个可读可写的字符串,该字符串是URL的锚部分(从#号开始的部分).语法location.hash刚开始我真不知道hash有什么用,直到我在项目中遇上一个最大的问题.而且很恶心的体验 ...
- "Cannot declare member function ...to have static linkage"错误
英文解释: if you declare a method to be static in your .cc file. The reason is that static means somethi ...
- Dubbo模块介绍
一.Dubbo 整体框架 Dubbo主要有:Config 配置层.Proxy服务代理层.Registry注册中心层.Cluster 路由层.Monitor监控层.Protocol远程调用层.Excha ...
- git之log
1 查看提交的具体文件 git log --oneline --stat 可参考: http://www.cnblogs.com/BeginMan/p/3577553.html
- 用Json Template在Azure上创建Cisco CSR路由器
Azure的ARM模式可以通过Json的模板创建VM.本文以Cisco的CSR的image为例,介绍如何用Json的创建VM. 一.Cisco CSR的Image 首先把Cisco CSR的image ...
- HDU5468(dfs序+容斥原理)
Puzzled Elena Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...