字符串分割

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
	ifstream readfile;
	readfile.open("八卦图数据源.txt");
	string str;
	string oldstr="";
    do{
    	readfile>>str;
    	if(str==oldstr){
    		break;
		}
		oldstr=str;
    	cout<<str<<"   x:"<<str.substr(0,str.find(":"))<<"   z:"<<str.substr(str.find(":")+1)<<endl;
	}while(str.size()>2&&str.find(":")>0&&str.find(":")<str.size());
	return 0; 
}

  

posted @ 2022-10-02 07:56  chenruolin1  阅读(23)  评论(2)    收藏  举报