xmcword
void fun(string a)
{
    for(int i=0;i<a.length();i++)
    {        
        cout<<a[i];
        usleep(10000);
        }
        cout<<"\n";
    
}
void slow(const string line,int t)
{
    for(int i;i<=line.length();i++)
    {
        cout<<line[i];
        usleep(t);
    }
}

这个就是函数了!

我们看看怎么使用

1、打好代码

#include <iostream>
using namespace std;
void fun(string a)
{
    for(int i=0;i<a.length();i++)
    {        
        cout<<a[i];
        usleep(10000);
        }
        cout<<"\n";
    
}
void slow(const string line,int t)
{
    for(int i;i<=line.length();i++)
    {
        cout<<line[i];
        usleep(t);
    }
}
int main()
{

    return 0;
}

2、使用

#include <iostream>
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
void fun(string a)
{
    for(int i=0;i<a.length();i++)
    {        
        cout<<a[i];
        usleep(10000);
        }
        cout<<"\n";
    
}
void slow(const string line,int t)
{
    for(int i;i<=line.length();i++)
    {
        cout<<line[i];
        usleep(t);
    }
}
int main()
{
    fun("1212121212121212");
    return 0;
}

3、结构

//以fun为例子
void fun(string a)//取名字随便比如void fun,void a,void b…… 
{
    for(int i=0;i<a.length();i++)//循环输出里面的字符
    {        
        cout<<a[i];
        usleep(10000);//等待时间,就是几微秒一个字
        }
        cout<<"\n";//换行
    
}

相关文章:

  • 2021-09-19
  • 2021-04-15
  • 2021-03-31
  • 2021-12-09
  • 2021-05-02
  • 2021-07-30
  • 2021-07-22
  • 2021-09-08
猜你喜欢
  • 2022-01-13
  • 2021-09-19
  • 2021-12-18
  • 2021-09-19
  • 2021-11-23
  • 2021-05-23
  • 2021-09-19
相关资源
相似解决方案