Thread: Equidistant Letter Sequencing

  1. #31
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by dwks
    Did you see this tutorial? http://www.cprogramming.com/tutorial/lesson10.html

    You can just read the filename in like normal with cin.
    This is what I am doing:

    // open the file to read in the text
    ifstream file;
    file.open(TEXTFILE);

    Thanks.

  2. #32
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    See Daved's post if you're using a string.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #33
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Yes, its working now.

    I am seperating everything into working functions as my next step.

    After that I will transfer the output to a file. The ouput being a grid doesn't seem to tough to manage.

    Also, I would like to be able to output the found searchwords in color in order to highlight them for the user. How do I change the color of the text being outputed to a file?

    Thanks.

  4. #34
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Its working now as output to a file. I am not sure how to output in color text though.

    Thanks.

  5. #35
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    How do I set the character it stops reading at? It is stopping at /n right now, but I wanted it to read the whole file all the way through.

    Thanks.

  6. #36
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Could I use the ignore()? How do I ignore all of the say spaces or /n characters and just read in all of the text characters in file?

    Thanks.

  7. #37
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    To read the entire contents of a file into a string, you could use getline in a loop, or you can use a stringstream like this example (important parts bolded):
    Code:
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    
    int main()
    {
        std::ifstream ifs("input.txt");
        std::stringstream sstr;
        sstr << ifs.rdbuf();
    
        std::string file_contents = sstr.str();
    
        std::cout << file_contents;
    }

  8. #38
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by Daved
    To read the entire contents of a file into a string, you could use getline in a loop, or you can use a stringstream like this example (important parts bolded):
    Code:
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    
    int main()
    {
        std::ifstream ifs("input.txt");
        std::stringstream sstr;
        sstr << ifs.rdbuf();
    
        std::string file_contents = sstr.str();
    
        std::cout << file_contents;
    }
    Thanks, it works now with this method. I was trying get a minute ago and it inserted extra characters.

    Now to finish seperating into functions and alow for simultaneously allowing for multiple searches with different skips.

    Also, does anyone have a solution to outputing in colored text? I can't find anything on outputing to a file using colored text.

    Thanks.

  9. #39
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You cannot output colored text in simple text files. To make it colored in the console, you need special console based commands that depend on your platform. Check out adrianxw's tutorial for information on that. To make a file have colored text, you'll have to write out the data in a special format like rtf. That's a lot more advanced than your current code seems to be ready for, but you can look into it by looking up the Rich Text file format.

  10. #40
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by Daved
    You cannot output colored text in simple text files. To make it colored in the console, you need special console based commands that depend on your platform. Check out adrianxw's tutorial for information on that. To make a file have colored text, you'll have to write out the data in a special format like rtf. That's a lot more advanced than your current code seems to be ready for, but you can look into it by looking up the Rich Text file format.
    Yes, how do I go about outputing RTF? Is there an article on it?

    Thanks.

  11. #41
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I'm sure there are a bunch, although probably not at this site. Did you search for one? It's way too complicated for me to describe here, even if I knew the syntax.

  12. #42
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by Daved
    I'm sure there are a bunch, although probably not at this site. Did you search for one? It's way too complicated for me to describe here, even if I knew the syntax.
    I think it might be better if I simply transfered my program into windows first.

    I have programmed in WIN32 before, but it has been a while.

    Any suggestions on what I might use as the lay out for the program?

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I ...
    By geekrockergal in forum C Programming
    Replies: 21
    Last Post: 02-07-2009, 10:40 AM
  2. counting letter occurences in a string
    By pjr5043 in forum C++ Programming
    Replies: 35
    Last Post: 05-05-2008, 09:18 PM
  3. Advice requested, Code makes sense to me, not compiler
    By andrew.bolster in forum C Programming
    Replies: 53
    Last Post: 01-06-2008, 01:44 PM
  4. help using strings and mapping
    By trprince in forum C Programming
    Replies: 29
    Last Post: 12-01-2007, 04:01 PM
  5. Big Letter became small letter
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-13-2004, 02:04 PM