psyking's Profile User Rating: -----

Reputation: 20 Tradesman
Group:
Authors
Active Posts:
173 (0.08 per day)
Joined:
17-January 10
Profile Views:
11,290
Last Active:
User is offline Dec 29 2015 10:20 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Ford
Dream Kudos:
150

Latest Visitors

Icon   psyking has not set their status

Posts I've Made

  1. In Topic: How to read a std::string from a file in c++

    Posted 17 Sep 2015

    View Postnordik14, on 16 September 2015 - 06:17 PM, said:

    psyking, it worked!. Thank you


    Happy to help.
  2. In Topic: How to read a std::string from a file in c++

    Posted 15 Sep 2015

    View Postnordik14, on 15 September 2015 - 10:35 PM, said:

    psyking you have helped me too much but sadly it seems not to work yet and I thank you. I still have the \n at the end and when I print it I can verify because cout<<"-"<<imagen_name<<"-";
    gives me:

    -objects/brick2.bmp
    -Unable to load bitmap: Couldn't open objects/brick2.bmp

    There is still a difference when I do
    brickim[i]=load_map(imagen_name,1); //It does not work
    
    


    and

    brickim[i]=load_map("objects/brick2.bmp",1); //It does work and why?
    
    


    so this is kind of desperating. So is there another theory around it? or an alternative way to remove \n? or another way to verify if exists /n at the end of my string?. Thanks all.


    The reason that it has only been working by directly typing the location of the bitmap to load is because the newline has not been removed from the other string (which is what is trying to be fixed). So when SDL tries to find the image, it can't find a file that has a newline character in its name, which is why you are getting the error.

    Try using std::remove(imagen_name.begin(), imagen_name.end(), '\n'); instead and see if it makes a difference? If it doesn't, then try this (but try it before you try this):
    // compare the newline character to the last character in the string
    if('\n' == imagen_name[imagen_name.size() - 1])
    {
        // if it contains a newline character, take a substring of it excluding
        // the last character of the string (which is the newline character).
        imagen_name = imagen_name.substr(0, imagen_name.size() - 1);
    }
    
    
  3. In Topic: How to read a std::string from a file in c++

    Posted 15 Sep 2015

    View Postnordik14, on 15 September 2015 - 09:59 PM, said:

    yes I see this compiles very well but sorry I didn't catch it. Is the iter string the new string that contains my string? I'm no familiar with this type of data std::string::reverse_iterator.


    std::string::reverse_iterator (Reference page) is a type that will allow you to traverse the string backwards. For example:
    std::string Hello{ "Hello!" };
    for(std::string::reverse_iterator iter = Hello.rbegin(); iter != Hello.rend(); ++iter)
    {
        std::cout << *iter;
    }
    
    

    This will output !olleH to the console.

    What std::remove(iter, ++iter, '\n'); does is goes through a few characters in your string (starting from the last, to the character just before the last) and checks if the newline character is one of the characters in your string, if it is it removes it from your string.
  4. In Topic: How to read a std::string from a file in c++

    Posted 15 Sep 2015

    View Postnordik14, on 15 September 2015 - 09:43 PM, said:

    psyking It does not work. Let me show you that I code:
    std::string imagen_name(strtok(NULL,search.c_str()));
    std::string::reverse_iterator iter = imagen_name.rbegin();
    std::remove(iter, ++iter, '\n');
    
    


    The compile error is:
    levels.c: In function ‘void load_pattern(std::string)’:
    levels.c:444:4: error: ‘remove’ is not a member of ‘std’
    std::remove(iter, ++iter, '\n');
    ^
    levels.c:444:4: note: suggested alternative:
    In file included from levels.c:1:0:
    /usr/include/stdio.h:178:12: note: ‘remove’
    extern int remove (const char *__filename) __THROW;
    ^
    make: *** [levels.o] Error 1

    Is there anything I did wrong?
    Thanks



    You need to include the algorithm header #include <algorithm>.
  5. In Topic: How to read a std::string from a file in c++

    Posted 15 Sep 2015

    View Postnordik14, on 15 September 2015 - 09:15 PM, said:

    so is there is any way to fix it? I've looked before but for a std::string always keeps the \n


    Check my previous post and see if that works for you.

My Information

Member Title:
D.I.C Head
Age:
24 years old
Birthday:
February 8, 1992
Gender:
Location:
Everywhere there is a computer connected to the internet
Interests:
Running Cross Country and Track, running my own business, programming websites and software, and other things as well.
Full Name:
Null

Contact Information

E-mail:
Private

Friends

Comments

psyking has no profile comments yet. Why not say hello?