मैं एक टेक्स्टफाइल की प्रत्येक पंक्ति को पढ़ने की कोशिश कर रहा हूं जिसमें प्रत्येक पंक्ति में एक शब्द होता है और उन शब्दों को वेक्टर में डाल दिया जाता है। मुझसे यह कैसे होगा?टेक्स्ट फ़ाइल से लाइन पढ़ना और स्ट्रिंग को वेक्टर में डालना?
यह मेरा नया कोड है: मुझे लगता है कि इसमें अभी भी कुछ गड़बड़ है।
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
std::string line;
vector<string> DataArray;
vector<string> QueryArray;
ifstream myfile("OHenry.txt");
ifstream qfile("queries.txt");
if(!myfile) //Always test the file open.
{
cout<<"Error opening output file"<<endl;
system("pause");
return -1;
}
while (std::getline(qfile, line))
{
QueryArray.push_back(line);
}
if(!qfile) //Always test the file open.
{
cout<<"Error opening output file"<<endl;
system("pause");
return -1;
}
while (std::getline(qfile, line))
{
QueryArray.push_back(line);
}
cout<<QueryArray[0]<<endl;
cout<<DataArray[0]<<endl;
}
अब तक कोड के साथ आपको क्या समस्या है? – Mahesh
@ माहेश यह * अगर (! Myfile) * पहली समस्या हो सकती है। (मुझे खेद है .. एसटीएल सीखने की जरूरत है।) – Beginner
@RomanB: उस पंक्ति के साथ कुछ भी गलत नहीं है। – Puppy