Thread: Really quick silly question.

  1. #16
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Yes it is.

    I cant even begin to understand the line of code mir posted, heh.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then try
    std::ifstream next_page( hyperlinks[i].c_str() );
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Elysia View Post
    Horrible solution to a fundamental problem IMO.
    If your talking about the cast, I agree.

    But the transform is exactly the right tool for this. You want to convert each element in a STL container. Transform is the function designed to do this.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #19
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Yes it is.

    I can't even begin to comprehend the line of code mir posted, haha.

    EDIT: I know about second pages, totally :\.

    Thanks elysia, worked like a charm =).

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The cast makes it even more horrible.
    You shouldn't have to call a "transform" function just to convert each character in a string. It's a string class, so provide a tolower function, even if it's just in the std namespace. It could just be a wrapper for transform, but it should exist.
    The more I find out about the standard library, the more poorly designed it seems to me. I'm just at odds with it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    What do you prefer to use? is there like an 'alternate STL'? Or do you just code it all from scratch yourself @_@?

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    MFC is what I tend to use.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Sigh heh. Ok, now I'm getting segfaults. My intuition (which is often wrong as a novice programmer) tells me that it has to do with the fact that I'm calling this Crawl function from within itself...yet using an infile stream. I.e.

    Crawl instance 1 calls crawl instance 2 with an ifs called next_page.
    Crawl instance 2 then tries to call crawl instance 3 with an ifs ALSO called next_page. I just tried adding in a ifs.close() in the Crawl function before it calls any more, but that didn't fix it.

    Any hints? :x I'll gladly provide any more information you need.

    EDIT: On the topic of STL v MFC. So the...microsoft foundation library (?) has a better set of tools? Is it more widely used?

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Jozrael View Post
    Crawl instance 1 calls crawl instance 2 with an ifs called next_page.
    Crawl instance 2 then tries to call crawl instance 3 with an ifs ALSO called next_page. I just tried adding in a ifs.close() in the Crawl function before it calls any more, but that didn't fix it.

    Any hints? :x I'll gladly provide any more information you need.
    Segfault can mean a lot. If you don't have a debugger, try adding things such as cout to see if it's indeed a stack overflow.
    Otherwise it can be memory corruption.
    Posting code here can also help others help you debug your code.

    EDIT: Oh, also whats MFC stand for?
    Microsoft Foundation Classes
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Jozrael View Post
    Yes it is.

    I can't even begin to comprehend the line of code mir posted, haha.
    I wrote a nice long post to explain it all, but it got deleted when I accidentally pressed alt-left on my browser.

    I will say this:
    It does exactly what it says. Transform -- read convert -- each element in the range from the start to the end of the string, put the result in the target string -- which can be the same string . The conversion function is given as tolower. It helps to know that transform does elem=func(elem) for each element.
    Last edited by King Mir; 04-03-2008 at 08:25 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  11. #26
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    I'm fairly sure its memory corruption. I have a map of strings and a class called 'page' (i'm simulating a web crawler) and I just found out that none of the info is actually being stored in the map properly. When I try to access it, segfault.

  12. #27
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> So the...microsoft foundation library (?) has a better set of tools?
    No.

    They are different. One is standard and works everywhere you have a modern C++ compiler. MFC is for windows and Visual Studio only. If you have an MFC application for other reasons, then you might want to use some of the MFC containers, but otherwise stick to the standard classes.

    Also, Elysia's opinion on the standard library interface is different than many C++ experts. Just because one person doesn't like the setup doesn't mean it's bad. (Of course, just because the C++ standards committee decided on the standard interface doesn't mean it's perfect either.)

  13. #28
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    EDIT: I'm a retard. Fixed. lol.
    Last edited by Jozrael; 04-03-2008 at 07:47 PM.

  14. #29
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Edit: Foot in mouth x2?
    Last edited by Jozrael; 04-03-2008 at 08:29 PM.

  15. #30
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Quote Originally Posted by King Mir View Post
    Code:
    transform(source.begin(), source.end(), target.begin(),static_cast< int(*)(int) >(tolower));
    The STL was made to be generic. A single function just to transform strings to lower would be too specific. This unfortunately looks a little bad with the cast, but it's necessary because there are two tolower functions.
    I skipped the cast and it worked just fine. I wasn't aware of transform, t'is a little neater than the old brute force method.

    Code:
      void lowerCase(std::string &s)
          {
    
           std::transform(s.begin(), s.end(),
           s.begin(), std::tolower);
    
           std::cout<<s;  //Optional
          }
    
      lowerCase(anyString);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM