Writing Strings with a Delimiter - C++ File Stream

C++ examples for File Stream:stream

Description

Writing Strings with a Delimiter

Demo Code

#include <iostream> 
#include <string> 
#include <fstream> 

using namespace std; 

void WriteString(ofstream &file, string words) 
{ 
    file << words; //ww  w . j a  v  a2s . co  m
    file << ";"; 
} 

int main() 
{ 
    ofstream delimfile("../delims.txt"); 

    WriteString(delimfile, "a"); 
    WriteString(delimfile, "test"); 
    WriteString(delimfile, "this"); 
    WriteString(delimfile, "is"); 
    WriteString(delimfile, "a"); 
    WriteString(delimfile, "d"); 
    WriteString(delimfile, "I"); 

    delimfile.close(); 
    return 0; 
}

Related Tutorials