where is push.back documentation ?
« on: 24 July 2013, 23:31:34 »
Searched entire Class reference and i couldnt find anything about push.back. And i used it in my code [Thanks to Texus] and i want to read more about it. Since TextBox doesnt have push.back i need to find another way to take typed text from Text box so i can store it into .txt. This is how i done for Editboxes:

Code: [Select]
EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i));
Group1Names.push_back(EditBoxNames[i]->getText());
saveGroup1(Group1Names);  // function to save vector into .txt

saveGroup1(Group1Names) function:
Code: [Select]
void saveGroup1(std::vector<sf::String> strings)
{
std::ofstream snimiGrupu1;
int i = 0;
snimiGrupu1.open ("Group1.txt", std::ios::trunc);
        if (snimiGrupu1.is_open())
        {
            for (std::vector<sf::String>::iterator itr = strings.begin(); itr != strings.end(); ++itr)
            {
            snimiGrupu1 << "Name" + tgui::to_string(i+1) + ": ";
            snimiGrupu1 << itr->toAnsiString();
            snimiGrupu1 << "\n";
            i = i + 1;
            }
        }

        else
        {
        snimiGrupu1.close();
        }
snimiGrupu1.close();
}

But i cant use push.back on TextBox so i need article [wont torture anyone to writte me code] to read to find another solution. :)

with respect
wmbuRn

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: where is push.back documentation ?
« Reply #1 on: 24 July 2013, 23:38:15 »
push_back is a function from vector and has nothing to do with tgui.
So you might just want to look up some tutorials about the STL vectors to understand this better.

Re: where is push.back documentation ?
« Reply #2 on: 24 July 2013, 23:41:13 »
Ok. Thank you. Never done any GUI od 2d/3d programing so i never used vectors nor iterators :) so i didnt know are they part of tgui or standard c++.  its new to me :)


Texus you should use : https://lmgtfy.com/?q=vector%3A%3Apush_back lol :)

Thank you

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: where is push.back documentation ?
« Reply #3 on: 25 July 2013, 11:09:27 »
Quote
Texus you should use : https://lmgtfy.com/?q=vector%3A%3Apush_back lol :)
I prefer this one :)
With that last '!cpp' you even get to cplusplus.com immediately.

Re: where is push.back documentation ?
« Reply #4 on: 25 July 2013, 20:01:36 »
lol :) nice one.
 Anyway vectors are pain in the ... After reading all of the documents there is for vectors my head is going to explode but vectorName.clear() and vectorName.resize() nor vectorName.erase(begin, end) vectorName.swap() does not do the job i want. [dont mind the name vectorName its just for argument, and all the calls have their respective values]

So i am in a little confusion. I took values from groups with this code:
Code: [Select]
for (unsigned i = 0; i < 30; ++i)
    {
    tgui::EditBox::Ptr Ime = Group1->get("Ime" + tgui::to_string(i));
    sf::String ValueIme = Ime->getText();

    tgui::EditBox::Ptr Ime1napomene = Group1Napomene->get("Ime" + tgui::to_string(i));
    Ime1napomene->setText(ValueIme);



// Code down is irrelevant lets focus on code above.

    // Uzmi Prezime iz Group1
    tgui::EditBox::Ptr Prezime = Group1->get("Prezime" + tgui::to_string(i));
    sf::String ValuePrezime = Prezime->getText();
    // Prebaci prezime iz Group1 u Group1Napomene
    tgui::EditBox::Ptr Prezime1napomene = Group1Napomene->get("Prezime" + tgui::to_string(i));
    Prezime1napomene->setText(ValuePrezime);


    // Uzmi BrojTelefona iz Group1
    tgui::EditBox::Ptr BrojTelefona = Group1->get("BrojTelefona" + tgui::to_string(i));
    sf::String ValueBrojTelefona = BrojTelefona->getText();
    // Prebaci BrojTelefona iz Group1 u Group1Napomene
    tgui::EditBox::Ptr BrojTelefona1napomene = Group1Napomene->get("BrojTelefona" + tgui::to_string(i));
    BrojTelefona1napomene->setText(ValueBrojTelefona);

    // Uzmi DatumRodjenja iz Group1
    tgui::EditBox::Ptr DatumRodjenja = Group1->get("DatumRodjenja" + tgui::to_string(i));
    sf::String ValueDatumRodjenja = DatumRodjenja->getText();
    // Prebaci DatumRodjenja iz Group1 u Group1Napomene
    tgui::EditBox::Ptr DatumRodjenja1napomene = Group1Napomene->get("DatumRodjenja" + tgui::to_string(i));
    DatumRodjenja1napomene->setText(ValueDatumRodjenja);

    }
Lets examine it.
 tgui::EditBox::Ptr Ime = Group1->get("Ime" + tgui::to_string(i));  << Ime get EditBox named Ime + i
 sf::String ValueIme = Ime->getText();   << sf::String get a value.

That code was for transfering from Group1 to Group2. Can i use that sf::String Ime to write it to .txt file? And since its for loop sf::String ime will get diferent values, and each values will be stored in .txt [with std::ios::app ] Which is better solution than this:
Code: [Select]
EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i)); // EditBoxNames is vector<tgui::EditBox.....>
GroupNames.push_back(EditBoxNames[i]->getText());       // GroupNames is vector<sf::String>....
saveGroup1Names(GroupNames);                                    // function with iterations to save to file

The only problem is: How to save to file when inputed string is sf::String instead of std::string.
Here is my function to save to .txt when is std::string
Code: [Select]
void saveIt(sf::String Text)
{
std::ofstream snimi;
snimi.open("Imena.txt", std::ios::app);
for (unsigned int i = 0; i < 30; ++i)
{
snimi << "Name" + tgui::to_string(i+1) + ": ";
snimi << Text;
snimi << "\n";
}
snimi.close();
}

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: where is push.back documentation ?
« Reply #5 on: 25 July 2013, 20:09:14 »
Quote
sf::String::toAnsiString() will return an std::string from the sf::String.
So the line can be
Code: [Select]
snimi << Text.toAnsiString();

Re: where is push.back documentation ?
« Reply #6 on: 25 July 2013, 21:05:52 »
Quote
sf::String::toAnsiString() will return an std::string from the sf::String.

Dont know what to do with it :) Nevermind, will get back to reading documentation and will (hopefully) get it to work. Thanks for your help :)


EDIT: Solved it. Thank you
took me 12hrs to solve this, and it was simple noobish mistake. LOL.
« Last Edit: 26 July 2013, 02:56:26 by wmbuRn »