按指定格式的分割字符串(包含string和char*的转换)

#include 
#include 
#include 
#include   //strtok头文件
using namespace std;
int main()
{
     
	string tt;
	cin>>tt;
	char *s = (char*)tt.c_str();
	char *p = strtok(s,"->");
	cout<<p<<endl;
	while(p!=NULL){
     
		p = strtok(NULL,"->");
		cout<<p<<endl;
	}
	return 0;
}

string转char*

string s = "123";
char*p = (char*)s.c_str();

char*转string

char*p = "123456";
string s = p;

你可能感兴趣的:(C/C++基础,c++,c语言)