【发布时间】:2018-06-04 18:13:54
【问题描述】:
我正在开发一个程序,该程序使用函数和指针在用户输入句子后用空格替换逗号。
但是,当我运行程序时,我收到上述错误和另一个错误;
“C++“const char *”类型的值不能用于初始化“std::string *”类型的实体”
这个程序有问题,想知道这里是否有人可以在正确的方向上帮助我?
谢谢!
代码如下:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
void comma2blank(string* pString1);
int main()
{
string* String1 = " " ;
cout << "Tell me why you like programming" << endl;
getline(cin, *String1);
comma2blank(String1);
cout << " String 1 without comma is: " << *String1 << endl;
delete String1;
system("pause");
};
void comma2blank(string* pString1)
{
pString1->replace(pString1->find(','), 1, 1, ' ');
pString1->replace(pString1->find(','), 1, 1, ' ');
};
【问题讨论】:
标签: c++ string function pointers error-handling