Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WriteFile.cpp : main project file.
- #include "stdafx.h"
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace System;
- using namespace std;
- template<typename T>
- vector<T>
- split(const T & str, const T & delimiters) {
- vector<T> v;
- T::size_type start = 0;
- auto pos = str.find_first_of(delimiters, start);
- while(pos != T::npos) {
- if(pos != start) // ignore empty tokens
- v.emplace_back(str, start, pos - start);
- start = pos+1;
- pos = str.find_first_of(delimiters, start);
- }
- if(start < str.length()) // ignore trailing delimiter
- v.emplace_back(str, start, str.length() - start); // add what's left of the string
- return v;
- }
- int main(array<System::String ^> ^args)
- {
- ifstream readFile("TEST.TXT");
- string line;
- if (readFile) {
- cout << "found file" << endl;
- while (getline (readFile,line) ) {
- vector<string> s = split<string>(line, ":");
- cout << s[0] << endl << s[1] << endl;
- }
- } else {
- cout << "unable to open text file" << endl;
- ofstream out("TEST.TXT");
- if (out) {
- out << "LINE1:HELLO" << endl;
- out << "LINE2:WORLD" << endl;
- } else {
- cout << "COULD NOT CREATE FILE" << endl;
- }
- }
- int i;
- cin >> i;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement