As you may guess I'm pretty new to c++.
I'm asked to write a program which would read and out put data files. Now im halfway through (that's why I'll ask you not to mind lots of what is on current code) but I'm stuck on this certain error for quite a bit already and from what I've read around it might be a function inside function problem which is not allowed in c++, yet I'm not able to see it and that's why I am asking for help out here.
(I'm working with microsoft visual studio 2008 for that matter)

#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
//---------------------------------------------------------------
const char CDfv[] = "studentai.txt";
const char CRfv[] = "Rezultatai.txt";
const int CMaksimalus = 400;
//---------------------------------------------------------------
class Studentas
{
private:
    string pavardė;
    string vardas;
    int įmetai;
    int epažymiai;
public:
    Studentas();
    Studentas(string pav, string var, int įmet, int paž);
    ~Studentas();
    string DėtiPavardę();
    string DėtiVardą();
    int DėtiĮMetus();
    int DėtiPažymius();
    string ImtiPavardę();
    string ImtiVardą();
    int ImtiĮMetus();
    int ImtiPažymius();
};
//---------------------------------------------------------------
// Pradinių duomenų skaitymas iš failo.
void Duomenys (const char fv[], Studentas S[], int & n);
// Rezultatų spausdinimas į failą.
void Spausdinti (const char fv[], Studentas S[], int n);
//---------------------------------------------------------------
int main()
{
    setlocale(LC_ALL, "Lithuanian");
    //ofstream fr(CRezultatųFailas); fr.close();
    Studentas S[CMaksimalus]; int n;
    Duomenys(CDfv, S, n);
    Spausdinti(CRfv, S, n);
    return 0;
}
//---------------------------------------------------------------
Studentas::Studentas(string pav, string var, int įmet, int paž):pavardė(pav), vardas(var), įmetai(įmet), epažymiai(paž) { }
Studentas::Studentas(): pavardė(""), vardas(""), įmetai(0), epažymiai(0) { }
Studentas::~Studentas() { }
//---------------------------------------------------------------
string Studentas::ImtiPavardę()
{
    return pavardė;
}
//---------------------------------------------------------------
string Studentas::ImtiVardą()
{
    return vardas;
}
//---------------------------------------------------------------
int Studentas::ImtiĮMetus()
{
    return įmetai;
}
//---------------------------------------------------------------
int Studentas::ImtiPažymius()
{
    return epažymiai;
}
//---------------------------------------------------------------
string Studentas::DėtiPavardę()
{
    return pavardė;
}
//---------------------------------------------------------------
string Studentas::DėtiVardą()
{
    return vardas;
}
//---------------------------------------------------------------
int Studentas::DėtiĮMetus()
{
    return įmetai;
}
//---------------------------------------------------------------
int Studentas::DėtiPažymius()
{
    return epažymiai;
}
//---------------------------------------------------------------
void Duomenys (const char fv[], Studentas S[], int & n)
{                                                             // 1st error here
    ifstream fd{fv};                                            // 2nd error here
    string pav, string var, int įmet, int paž;
    fd > n;
    for (int i = 0; i < n; i++) {
        fd >> pav >> var >> įmet >> paž;
        S[i] = Studentas(pav, var, įmet, paž);
    }
    fd.close();
}
//---------------------------------------------------------------
void Spausdinti(const char fv[], Studentas S[], int n)
{
  ofstream fr(fv);
  fr << " Pavardė      Vardas       Įstojimo į Universiteta        Kursas\n";
  fr << "                                    metai                      \n";
  fr << "-------------------------------------------------------------\n";
  for (int i = 0; i < n; i++)
    fr << left << setw(20) << G[i].ImtiPav()
               << setw(15) << G[i].ImtiVardą()
       << "  " << fixed << right << setw(8)
       << setprecision(2) << S[i].ImtiĮMetus()
       << endl;
  fr << "-------------------------------------------------------------\n";
  fr.close();
}
1>------ Build started: Project: L3_2, Configuration: Debug Win32 ------
1>Compiling...
1>L3_2.cpp
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(100) : error C2601: 'fd' : local function definitions are illegal
1>        c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(99): this line contains a '{' which has not yet been matched
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(100) : error C2143: syntax error : missing ';' before '}'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(101) : error C2146: syntax error : missing ';' before identifier 'var'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(101) : error C2065: 'var' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(101) : error C2062: type 'int' unexpected
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(102) : error C2065: 'fd' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(102) : error C2065: 'n' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2143: syntax error : missing ')' before ';'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2143: syntax error : missing ';' before ')'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2143: syntax error : missing ';' before ')'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2065: 'i' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2065: 'n' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2065: 'i' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(103) : error C2059: syntax error : ')'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(104) : error C2146: syntax error : missing ';' before identifier 'fd'
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(104) : error C2065: 'fd' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(104) : error C2065: 'var' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(104) : error C2065: 'įmet' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(104) : error C2065: 'paž' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(105) : error C2065: 'S' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(105) : error C2065: 'i' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(105) : error C2065: 'var' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(105) : error C2065: 'įmet' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(105) : error C2065: 'paž' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(107) : error C2065: 'fd' : undeclared identifier
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(107) : error C2228: left of '.close' must have class/struct/union
1>        type is ''unknown-type''
1>c:\users\andriusa\desktop\ktu\programavimas\laborai\laboras 3\l3\l3\l3_2.cpp(108) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Build log was saved at "file://c:\Users\andriusa\Desktop\KTU\PROGRAMAVIMAS\laborai\Laboras 3\L3_2\L3_2\Debug\BuildLog.htm"
1>L3_2 - 27 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I've managed to sort it out with a little bit of help (some of errors were sort of really dumb, yet I do not blame myself much since I'm little bit new to this) but now pretty dumb question is, how to add/use text file with my program, where do I put one? somewhere in the same folder as .cpp file or add it somewhere in solution explorer?

This article has been dead for over six months. Start a new discussion instead.