将一个string字符串变量分解为字符输出

2014-11-24 03:11:19 · 作者: · 浏览: 1

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

#include
  
   
#include
   
     using namespace std; int main() { string str; cin>>str; cout<
    
     
string变量相当于是一个变长的字符数组,随着输入的字符串长度的长度的变化而变化。

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

#include
      
       
#include
       
         using namespace std; int main() { string str; cin>>str; cout<