C++ Syntax Error Issue

Hello all,

I am new to C++ and I need a little help. I am debugging some code I wrote, and I get the following error:


Error: String literal syntax error /Users/Desktop/macros/De.C:272:
Error: << Illegal operator for pointer 3 /Users/Desktop/macros/De.C:272:
Error: << Illegal operator for real number /Users/Desktop/macros/De.C:272:
(class G__CINT_ENDL)31961104
*** Interpreter error recovered ***


The interesting thing is that lines 250-290 are completely commented out. Isn't commented line skipped over?

I've also deleted white space out above the code, and the error moves accordingly- it's targeting a single line that's commented out. The line is:

 
// display << "De" << endl; 


I'm sure the display file is opened/closed right. The file is written to in other places and no error is generated.

Any help is GREATLY appreciated. I just never thought that code that's commented out could cause an error...isn't that part of the idea behind commenting?

thanks
Can I see the entire commented code? Make sure that you don't have stuff like this:

1
2
3
4
5
6
7
/*
comment
/*
comment
*/
uh oh, not commented!
*/ //errors! 
Sure, the code itself is quite long, but here's the part of interest (i'm sure the problem lies somewhere else though):

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
26
27
28
29
30
31
32

/* // Output  
 These calculations use histograms...check only
  display << "OLD WAY OF DOING THINGS...." << endl;
  display << "FULL RAPIDITY " << endl;
  display << "<N> from ROOT: "             << MeanN << endl;
  display << "<Pt> from ROOT: "            << MeanPt << endl;	
  display << "<pt> = <Pt>/<N> from ROOT: " << Mean_pt << endl;
  display << "Var(N) from ROOT: "           << Var_N << endl;
  display << "Cov(N,E) from ROOT: "        << Cov_NE << endl;  


// Use counters for calculations
  display << " " << endl;
  display << "De" << endl;
  display << "NEW WAY OF DOING THINGS...." << endl; 
  display <<  TotalPt << "TotalPt" << endl;                           
  display << "<Pt>: " << TotalPt/NumberOfEvents << endl;
  display << "<pt> = <Pt>/<N>:" << (TotalPt/double(NumberOfEvents))/Nchavg << endl;
  display << endl;

// D charged
  display << "For D: " << endl;
  display << "<N>_ch =" << Nchavg << endl;
  display << "<pt> = " << AveragePt/f<< endl;
  display << "The sum of (N_ch-<N_ch>)(Pt-<Pt>):" << f << endl;
  display << "The actual covariance(N_ch,Pt): " << F << endl;
  display << "The sum of (N_ch - <N_ch>)^2: " << h << endl;
  display << "The actual Variance(N_ch): " << H << endl;
  display << "D this way is: " << (F-(AveragePt/Nchavg)*(H))/(Nchavg*Nchavg) << endl;
  display << endl;
*/


So I'm outputing titles and variables to a file, line by line.

I understand this may not be the most efficient way of doing this, but it has worked in the past and still should.

Have you seen something like this before? thanks,
Last edited on
It doesn't seems like there is a problem with this, maybe send some more code (a bit before and a bit after the comment), or try
1
2
3
#if 0
//commented code here
#endif 

These preprocessor style comments can nest and you can uncomment it only by replacing #if 0 with #if 1
I notice that the error mentions the << operator and the file name is De.C.
Are you using C++ operations in a C file??

(or more to the point - shouldn't your file be called de.cpp instead of de.C ??)
Last edited on
I thought I had poured over all the code countless times, and as I went to post some code after the snippet I posted previously, I found the error:


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
26
// Use counters for calculations
  display << " " << endl;
  display << "De" << endl;
  display << "NEW WAY OF DOING THINGS...." << endl; 
  display <<  TotalPt << "TotalPt" << endl;                           
  display << "<Pt>: " << TotalPt/NumberOfEvents << endl;
  display << "<pt> = <Pt>/<N>:" << (TotalPt/double(NumberOfEvents))/Nchavg << endl;
  display << endl;

// D charged
  display << "For D: " << endl;
  display << "<N>_ch =" << Nchavg << endl;
  display << "<pt> = " << AveragePt/f<< endl;
  display << "The sum of (N_ch-<N_ch>)(Pt-<Pt>):" << f << endl;
  display << "The actual covariance(N_ch,Pt): " << F << endl;
  display << "The sum of (N_ch - <N_ch>)^2: " << h << endl;
  display << "The actual Variance(N_ch): " << H << endl;
  display << "D this way is: " << (F-(AveragePt/Nchavg)*(H))/(Nchavg*Nchavg) << endl;
  display << endl;
*/

  display << "Max output: " << MaximumVal << endl;
  display << "Min output: " << MinimumVal << endl;
  display << "Max input: " << Maxinput << end
  display << "Min input:" << Mininput << endl;



On the second line from the bottom, you can see the error. I still think it's kinda weird that the error prints so far from where it actually occurred, but I'm grateful to find it nonetheless. Thanks for your suggestion R0mai.

guestgulkan,

I believe you're also right but I'm not compiling this code in just something like Microsoft Visual, it's more of a C/C++ hybrid front end which I use in my work. Thanks for your help.

and now i just feel dumb....
Topic archived. No new replies allowed.