Hi guys.
I need help with reading a .txt file, and converting every line into a string. For instance, file path is D:\file.txt...
What libraries i need, how to open it, and read one line at a time?
Thx in advance, I've been trying for hours now.
Thx for this, its getting better i guess, 2 errors now:
1>c:\visual studio 2005\projects\nenadzivic-asocijacije\asocijacije\glavni kod.cpp(38) : error C2664: 'fgets' : cannot convert parameter 3 from 'std::ifstream' to 'FILE *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\visual studio 2005\projects\nenadzivic-asocijacije\asocijacije\glavni kod.cpp(91) : error C2660: 'std::basic_ifstream<_Elem,_Traits>::close' : function does not take 1 arguments
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
Yes, i agree with Kiana, i guess thats the main problem. Now, can u tell me what sholud i change in the code in order to fix it. 'Cause i have a C book, and i work in C++....
#include <iostream> // for cout
#include <fstream> // include fstream
int main(){
std::string pojmovi[40], kontrolni_hit; // use std::string instead of char array
int redni,boolean,brojac[8],broj_rundi,broj_ekipa,duzina_runde;
// prefix with std:: !
std::ifstream baza;
baza.open("probni.txt");
for (int i=1;i<=10;i++)
{
getline(baza,pojmovi[i]); // <--- get line from 'baza' and put it into 'pojmovi[i]'
std::cout <<pojmovi[i]<<std::endl; // use cout to print std::strings
};
}