为了账号安全,请及时绑定邮箱和手机立即绑定

程序运行到这里的时候出现故障 但是并非是调试出错 而是运行之后程序不能继续运行有点像“无响应”

程序运行到这里的时候出现故障 但是并非是调试出错 而是运行之后程序不能继续运行有点像“无响应”

C++
莫回无 2023-04-20 19:15:07
请问一下这个函数的具体用法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条经验 获得超4个赞

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.


查看完整回答
反对 回复 2023-04-23
?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

string-》c风格字符串要转换的。成员函数c_str();

查看完整回答
反对 回复 2023-04-23
  • 2 回答
  • 0 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信