Prikaz jedne poruke
Stara 19.3.2012, 21:23   #2
Belphegor
V.I.P. Programiranje
 
Član od: 29.8.2007.
Lokacija: Valjevo
Poruke: 1.349
Zahvalnice: 983
Zahvaljeno 371 puta na 280 poruka
Određen forumom Re: Treba mi pomoć oko pisanja programa [C++]

Evo nesto na brzinu, mozda moze i bolje:

Recimo evaluate.txt je ovaj:
Kod:
1 97 1 1 MZ 84 -99 -99 -99 -99 162 ABC
1 31 1 1 MZ 84 -99 -99 -99 -99 107 ABC
1 42 1 1 MZ 84 -99 -99 -99 -99 184 ABC
1 56 1 1 MZ 84 -99 -99 -99 -99 111 ABC
ima 12 kolona i hoces da izvuces vrednost iz 2 i 11:

Kod:
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>

int main()
{
    try
    {
        std::fstream in("evaluate.txt", std::ios::in);

        std::vector<std::string> vout;
        std::string line;
        while(std::getline(in, line))
        {
            std::stringstream sstr;
            sstr << line;
            std::string tmp, out;
            for(std::size_t i = 0; i < 12; ++i)
            {
                if(i == 1)
                {
                    sstr >> out;
                    out += ' ';
                }
                else if(i == 10)
                {
                    tmp.clear();
                    sstr >> tmp;
                    out += tmp;
                    vout.push_back(out);
                    out.clear();
                }
                else
                {
                    sstr >> tmp;
                }
            }
        }

        const auto& end = vout.end();
        auto it         = vout.begin();
        for(; it != end; ++it)
        {
            std::cout << *it << std::endl;
        }
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    std::cin.ignore();
    return 0;
}
output:
Citat:
97 162
31 107
42 184
56 111
s'tim da prvo treba preskociti prvih par redova. E sad za setanje po folderima trazi po MSDN-u FindFirstFile i FindNextFile
Belphegor je offline   Odgovor sa citatom ove poruke
Sledeći korisnik se zahvaljuje korisniku Belphegor na korisnoj poruci:
Demosten (21.3.2012)