Created
June 28, 2019 23:57
-
-
Save szolotykh/1c1aafd41986b3399cbf225263160354 to your computer and use it in GitHub Desktop.
CString Split C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <sstream> | |
#include <iostream> | |
#include <vector> | |
#include "cstring.h" | |
using namespace std; | |
void CString::split(std::vector<CString>& strings) | |
{ | |
stringstream ss; | |
ss << m_string; | |
while(!ss.eof()) | |
{ | |
string out; | |
ss >> out; | |
strings.push_back(out); | |
} | |
} | |
std::ostream& operator<<(std::ostream& os, const CString& str) | |
{ | |
os << str.m_string; | |
return os; | |
} | |
std::istream& operator>>(std::istream& os, CString& str) | |
{ | |
os >> str.m_string; | |
return os; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CString | |
{ | |
public: | |
CString () | |
:m_string("") | |
{ | |
} | |
CString (std::string str) | |
:m_string(str) | |
{ | |
} | |
CString(const char str[]) | |
:m_string(str) | |
{ | |
} | |
public: | |
void split(std::vector<CString>& strings); | |
friend std::ostream& operator<<(std::ostream& os, const CString& str); | |
friend std::istream& operator>>(std::istream& os, CString& str); | |
private: | |
std::string m_string; | |
}; | |
std::ostream& operator<<(std::ostream& os, const CString& str); | |
std::istream& operator>>(std::istream& os, CString& str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include "cstring.h" | |
using namespace std; | |
int main() | |
{ | |
CString str = "What is your name"; | |
vector<CString> strings; | |
str.split(strings); | |
for(auto s : strings){ | |
cout << s << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment