where is push.back documentation ?

Started by wmbuRn, 24 July 2013, 23:31:34

wmbuRn

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:


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:

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

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.

wmbuRn

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

QuoteTexus 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.

wmbuRn

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:

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:

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

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();
}
And i get error in line " snimi << Text; " Gcc complain that it cant do anything with Text. error: no match for 'operator<<' in 'snimi << Text'
Any solution to this? Since i cant bust my head again with vectors.

texus

QuoteAnd i get error in line " snimi << Text; " Gcc complain that it cant do anything with Text. error: no match for 'operator<<' in 'snimi << Text'
Any solution to this? Since i cant bust my head again with vectors.
sf::String::toAnsiString() will return an std::string from the sf::String.
So the line can be
snimi << Text.toAnsiString();

wmbuRn

#6
Quotesf::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.