Nov 26, 2012 at 7:49am UTC
Is there a way i can "comment out" lines in a txt file that im reading data from? The actual prefix im looking for to decide wheather or not to ignore the line dosent really matter, just thought comment's would be the best example. So kinda like- (yes im sure this is wrong, its just an example)
Code
1 2 3 4 5 6
if (GetLine = "//" ){
//ignore it
}
File >> line1;
File >> line2;
whatever.txt
Results
1 2 3
line1 = 1;
line2 = 2;
Last edited on Nov 26, 2012 at 7:50am UTC
Nov 26, 2012 at 8:21am UTC
no you can't. you first have to read the line in order to know it says: Dont read me
but you can decide after you read it, what you want to do with it
Nov 26, 2012 at 8:31am UTC
you can ignore .
use File.ignore(1,\'n') ignore next line
then read another line
Nov 27, 2012 at 3:51am UTC
Yes, you can ignore lines in a file (sorta)...
First, create a file in a directory of your choosing... I put the following data in the text file:
----------FILE-------------
;Database
Do this here
123
33
79
---------EOF----------------
The code...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
const string aFile = "C:/YOUR_DIRECTORY/Example.txt" ;
ifstream f(aFile);
string line;
while (!f.eof()) {
getline(f,line);
if (line.length() == 0 || line[0] == ';' )
cout << "IGNORE LINE\n" ;
else
cout << line << "\n" ;
}
system("pause" );
return 0;
}
The screen printout looked like this:
IGNORE LINE
Do this here
IGNORE LINE
123
33
79
Last edited on Nov 27, 2012 at 3:51am UTC
Nov 27, 2012 at 5:44am UTC
cant getline read until it hits something? traditionally thats endl but can't it be the line?