請問一下這個函數的具體用法void set_about(string about){for(int i = 0;i < (int)(about.length() / 2) / 30 && i < 25;i++)for(int j = 0;j <= 29;j++){if(about.substr(i * 30 * 2 + j * 2,2) == LINEFEED)about.insert(i * 30 * 2 + j * 2,BLANK,0,2);set_pixel(i + 8,j + 8,about.substr(i * 30 * 2 + j * 2,2));}for(int i = 0;i < (about.length() / 2) % 30;i++)set_pixel((int)(about.length() / 2) / 30 + 8,i + 8,about.substr((int)((about.length() / 2) / 30) * 30 * 2 + i * 2,2));}以上是我所寫的一個函數,其中set_pixel()是用于打點的,在此之前此函數并未出現故障 而LINEFEED 和 BLANK是字符串常量,
2 回答

收到一只叮咚
TA貢獻1821條經驗 獲得超5個贊
string的成員函數insert有以下多種重載:
string &insert(int p0, const char *s);——在p0位置插入字符串s
string &insert(int p0, const char *s, int n);——在p0位置插入字符串s的前n個字符
string &insert(int p0,const string &s);——在p0位置插入字符串s
string &insert(int p0,const string &s, int pos, int n);——在p0位置插入字符串s從pos開始的連續n個字符
string &insert(int p0, int n, char c);//在p0處插入n個字符c
iterator insert(iterator it, char c);//在it處插入字符c,返回插入后迭代器的位置
void insert(iterator it, const_iterator first, const_iteratorlast);//在it處插入從first開始至last-1的所有字符
void insert(iterator it, int n, char c);//在it處插入n個字符c
以下是第二行性能的舉例代碼:
//#include "stdafx.h"//If the vc++6.0, with this line. #include <string> #include <iostream> using namespace std; // int main( void ){ string a= "1234567890" ,b= "abcdefghijklmn" ; a.insert(3,b,5,4); cout << a << endl; return 0; } |
輸出是123fghi4567890.
- 2 回答
- 0 關注
- 165 瀏覽
添加回答
舉報
0/150
提交
取消