Opening .txt file

here is the code i wrote i am not sure whats wrong but the contxs.txt file its not opening. The code the just skips to end from the part where i am trying to read anything from context file.

#include <conio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

int main()
{
char n1[30];
string noun,line,con;
size_t pos, len,i,j;
vector <string> c1;


ifstream contextfile;
contextfile.open("CONTXS.txt");
ifstream datafile;
datafile.open("COOCS.txt");



if (datafile.is_open())
{
==>> while (contextfile.is_open()) <<==
{
getline(contextfile, con);
{
for (i = 1; i <= 6; i++)
{
cout << "enter the Noun:";
cin.getline(n1, sizeof(n1));
string n1_1(n1);

while (noun != n1_1)
{
Last edited on
yes because after getline (contwxtfile, con); it just ends there its not opening that file
Some quick things, I you allow me.
The first "if" has no sense, since the "while" asks the same question.
If contextfile says that is open ... then is open. Another thing is what does getline do. What are the contents of the file? Text? Then why to use ifstream? Why don't you use istringstream instead?
std::istringstream does not read from files.
the text file contains :

belabor 0.086
finer 0.086
eyewear 0.44
marketing strategy 0.17
coherence 0.11
dictum 0.12
interdependence 0.14
physical reality 0.14
single image 0.14
race car 0.093
circa 0.48
outbound 0.5

similar kind of text
in getline i am trying to get just the first line
Is the file name correct? Is it in the right location?

1
2
3
4
5
6
7
8
9
10
11
int main()
{
  std::ifstream in("infile.txt");
  std::string line;

  while (std::getline(in, line)) {
    std::cout << "line: \"" << line << "\"" << std::endl;
  }

  in.close();
}
turns out i placed the file in wrong folder. Thanks guys!!!
Topic archived. No new replies allowed.