File Output with color?

im wokring on a project that lists DVD's in a linked list to a Output File and I was wondering if they is a way to make every other one a different color so that way it went black to say red black red black red and alternated. i know there is a system color command but does that only work when you run it though dos?

Thanks for your guys help
Standard text files (ASCII files) do not have color attributes, so no.
Unless you a writing to a different file format.
You could output to HTML.
I'm not exactly clear as to where you want the colors. Embedded in the text file? You could try ANSI escape sequences but the key will be how/where you display the file to interpret them. Colored as it displays? Look into ncurses.
helios wrote:
You could output to HTML.

That is a brilliant idea. (Assuming the OP can support displaying it)
Last edited on
Something like this?
(Uses a table.)
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
39
40
41
42
#include <fstream>

template <typename Container>
bool write_html( const std::string& filename, const Container& container )
  {
  std::ofstream outf( filename.c_str() );
  if (!outf) return false;

  outf << "<html>\n"
          "<head>\n"
          "  <style type=\"text/css\"><!--\n"
          "    .eggshell { background-color: #FEFFFE; }\n"
          "    .blueline { background-color: #DDEEFF; }\n"
          "    table { font-family: \"Courier New\", \"Courier\", monospace; }\n"
          "  --></style>\n"
          "</head>\n"
          "<body>\n\n"

          "  <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n";

  bool b = false;
  for (typename Container::const_iterator
       elt  = container.begin();
       elt != container.end();
       elt++)
    {
    outf << "    <tr class=\""
         << ( b
            ? "eggshell"
            : "blueline")
         << "\"><td>"
         << *elt
         << "</td></tr>\n";
    b = !b;
    }

  outf << "  </table>\n"
          "</body>\n"
          "</html>\n";

  return true;
  }
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
  {
  vector <string> v;
  v.push_back( "one" );
  v.push_back( "two two" );
  v.push_back( "three three three" );
  v.push_back( "one two three four" );
  v.push_back( "the end" );

  cout << ( write_html( "test.html", v )
          ? "yeah!\n"
          : "fooey!\n");
  return 0;
  }

Simple and, well, simple.
thanks for the responses i just want to output to a standard .txt file. its not to important just wanted to try to make my project for school stand out more.
Topic archived. No new replies allowed.