wildpuma
7th January 2014, 19:50
I have the problem with opening file in Qt using ifstream. Program can`t read data from text document and display on the screen. The same code works in CodeBlocks or other compiliers. I have installed Qt 5.2 Version and created Plain C++ Project. I didn`t try other Version of Qt.
#include<fstream>
#include <vector>
int main()
{
std::vector<std::string> v;
std::string line(""), new_line("");
std::ifstream in("main.cpp");
while(getline(in, line))
v.push_back(line);
for(int j = 0;j<v.size();j++){
new_line += v[j]+"\n";
}
std::cout<<new_line<<std::flush;
}
When I created new test example
std::ifstream myfile("tekst.txt");
if(myfile.is_open())
std::cout<<"Yes!"<<std::endl;
else
std::cout<<"No!"<<std::endl;
The answer of the program was "No". It occured program has no access to file. Maybe someone has the same problem. Should I change settings somewhere?
#include<fstream>
#include <vector>
int main()
{
std::vector<std::string> v;
std::string line(""), new_line("");
std::ifstream in("main.cpp");
while(getline(in, line))
v.push_back(line);
for(int j = 0;j<v.size();j++){
new_line += v[j]+"\n";
}
std::cout<<new_line<<std::flush;
}
When I created new test example
std::ifstream myfile("tekst.txt");
if(myfile.is_open())
std::cout<<"Yes!"<<std::endl;
else
std::cout<<"No!"<<std::endl;
The answer of the program was "No". It occured program has no access to file. Maybe someone has the same problem. Should I change settings somewhere?