Void data types

I can't figure out how to save the void data types onto a file. Can you guys help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include <iostream>
#include <fstream>
#include <string>
using namespace std;

void displayStars(int = 0, int = 0);

int main()
{
	displayStars(2,1);
	displayStars(4,1);
	displayStars(8,1);
	displayStars(16,1);
	
	ofstream outputFile;
	string Pattern.txt;
	outputFile.open("Pattern.txt");
	
	char displayStars();
	
	outputFile << displayStars(2,1);
	outputFile << displayStars(4,1);
	outputFile << displayStars(8,1);
	outputFile << displayStars(16,1);
	
	outputFile.close();
	return 0;
}

void displayStars(int cols, int rows)
{
	for(int down = 0; down < rows; down++)
	{
	for (int across = 0; across < cols; across++)
		cout << "+";
		cout << endl;
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

void display_stars( int rows = 0, int cols = 0, char star_character = '+', std::ostream& stm = std::cout );

int main()
{
    display_stars( 7, 10 ); // star_character is '+' (default), output stream is std::cout (default)
    display_stars( 5, 17, '*' ); // star_character is '*', output stream is std::cout (default)

    const std::string file_name = "Pattern.txt" ;

    {
        std::ofstream file(file_name); // open the file for input

        // output stream is file
        display_stars( 7, 10, '+', file ); // star_character is '+', output stream is file
        display_stars( 5, 17, '*', file ); // star_character is '*', output stream is file
    } // file is automagically closed when its life-time is over

    // dump the contents of the file to see what was written into it
    std::cout << "\n-----------------\ncontents of file " << std::quoted(file_name) << ":\n------------------\n" ;
    std::cout << std::ifstream(file_name).rdbuf() ;
}

void display_stars( int rows, int cols, char star_character, std::ostream& stm )
{
    for( int down = 0; down < rows; ++down )
    {
        for( int across = 0; across < cols; ++across ) stm << star_character ;
        stm << '\n' ;
    }
    stm << '\n' ;
}

http://coliru.stacked-crooked.com/a/bd74be9236a9557e
Topic archived. No new replies allowed.