띄어쓰기로 string 분리 저장하기
std::string sentence = "Hello world! This is a sentence.";
std::vector<std::string> words;
// stringstream을 사용하여 string을 띄어쓰기로 분리
std::stringstream ss(sentence);
std::string word;
while (ss >> word) {
words.push_back(word);
}
특정 구분자로 string 분리 저장하기
string str = "apple,banana,orange";
vector<string> vec;
stringstream ss(str);
string token;
while(getline(ss,token,','))
vec.push_back(token);
for(const auto& ele : vec)
cout << ele << endl;
파일 열어서 쓰기
char arr[]= "Hello, World!";
std::ofstream file("output.txt");
if (file.is_open()) {
file << arr;
file.close();
}
파일 열어서 읽어오기
ifstream file("input.txt");
vector<string> row;
if(file.is_open())
{
string str;
while(getline(file,str))
{
row.push_back(str));
}
file.close();