c++输入输出
2017-03-20 21:56
204 查看
这是一个调试程序
#include<iostream> using namespace std; class Solution { public: void replaceSpace(char *str,int length) { if(str == NULL || length<=0) return; int length_origin = 0; int blank = 0; while(*str != '\0'){ if(*str == ' '){ blank++; length_origin++; str++; } else{ length_origin++; str++; continue; } } cout<<'a'<<endl; int length_new = length_origin+2*blank; cout<<'a'<<endl; if(length_new > length) return; else{cout<<'b'<<endl; char *str_new = str+2*blank; cout<<'b'<<endl; while(str_new != str){ if(*str == ' '){ *str_new = '0'; *(str_new-1) = '2'; *(str_new-2) = '%'; str_new = str_new -3; str--; } else{ *str_new =*str; str_new--; str--; } } } } }; int main(){ // cout<<'a'; char str[] = "we are happy"; cout<<str<<endl; Solution replace; replace.replaceSpace(str,50); cout<<'a'; cout<<'a'<<endl; cout<<'a'<<endl; cout<<str<<endl; return 0; }
输出的效果为:
we are happy a a b b aa a we%20are%20happy
c++的输入输出是cin,cout
cout后面加endl会在输出后加一个回车‘\n’,若不加endl,下面的输出会接着上面一个输出后面
相关文章推荐
- c++输入输出控制
- java 和 c++ 之间通过 控制台 输入输出 传递数据
- C++输入输出流
- C/C++文件输入输出操作——FILE*、fstream、windowsAPI
- C++总是能让我想起什么(4)——C++输入输出流
- C++中输入输出操作
- C++输入输出重载中的问题(转换IP为二进制)
- C++输入输出零散点
- C/C++文件输入输出操作——FILE*、fstream、windowsAPI
- C++中的基本类型及输入输出格式
- 个人编写的C++教程(不断连载中)——标准输入输出(1)
- C++文件输入输出简明说明
- C/C++ 标准输入输出重定向
- C++文件输入输出
- c++中的io输入输出
- C++基本数据类型与输入输出
- c++格式化输入输出
- 简单的程序,C++输入输出
- C++和C的语法区别_输入输出
- 有个问题,是关于C++文本输入输出的