473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error C2001: newline in constant-Help!

1
Trying to create a program which reads and echos the contents of an input data file, which consists of two records. When I complile my code I keep getting a "error C2001: newline in constant" error. Read every forum regarding the "error C2001: newline in constant" error but I am still not clear as to where my code is erroring out. Can anyone help point me in the right direction?
Thanks

My code:

Expand|Select|Wrap|Line Numbers
  1. //************************************************************************************************
  2. // Test Program: Chapter 6            A noninteractive program which reads and echos input data file.
  3. //            
  4. //
  5. //************************************************************************************************
  6. #include<iostream.h>
  7. #include<iomanip>
  8. #include<fstream>                    //For input data file.
  9. using namespace std;
  10.  
  11.  
  12. int main()
  13. {
  14.     float side;                        // 1st input data field on each record: must be >=0
  15.     float area;                        // 2nd input data filed on each record: must be >=0
  16.     ifstream inFile;                // Data file: each record shows side 
  17.  
  18.  
  19.     //Attempt to open the input data file
  20.     inFile.open("sidearea.dat");
  21.     if(!inFile)                    // If file can't be found (we're in a fail state):
  22.     {
  23.         cout<<("Unable to open input file, program abnormally ended\n");
  24.         return 1;                    // Terminate program early, with return code=1:
  25.     }
  26.  
  27.     //Get first pair of input data values for side and area, then echo print:
  28.     inFile>>side>>area;
  29.     cout<<"Record1:Side is"<<side<<"and area is"<<area<<endl;
  30.  
  31.     //Check 1st record for I/O errors, then for valid data values:
  32.     ;if(!inFile)
  33.     {
  34.         cout<<"I/O Error on input file, program abnormanlly ended\n";
  35.         return 1;
  36.     }
  37.     else
  38.     {
  39.         if(side<0)
  40.             cout<<"Warning side is invalid, must be = or > 0"<<endl;
  41.         if(area=(side*side))
  42.             cout<<"Warning area is invalid, must not be = to side square"<<endl;
  43.     }
  44.  
  45.     //Get second pair of input data values for side and area
  46.     inFile>>side>>area;
  47.     cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
  48.  
  49.     //Check 2nd record for I/O errors, then for valid data values:
  50.     ;if(inFile)
  51.     {
  52.         cout<<("I/O Error on input file, program abnormally ended");
  53.         return 1;
  54.     }
  55.     else
  56.     {
  57.         if(side<0)
  58.             cout<<"Warning side is invalid, must be = or > 0"<<endl;
  59.         if(area=(side*side))
  60.             cout<<"I/O Error on input file, program abnormally ended"<<endl;
  61.             }
  62.  
  63.     //Terminate program normally:
  64.     cout<<"No I/O Errors in input file, pgm. terminated normally"<<endl;
  65.     return 0;
  66. }
Feb 20 '07 #1
3 15417
sicarie
4,677 Expert Mod 4TB
Trying to create a program which reads and echos the contents of an input data file, which consists of two records. When I complile my code I keep getting a "error C2001: newline in constant" error. Read every forum regarding the "error C2001: newline in constant" error but I am still not clear as to where my code is erroring out. Can anyone help point me in the right direction?
Thanks

My code:

/************************************************** **********************************************
// Test Program: Chapter 6 A noninteractive program which reads and echos input data file.
//
//
//************************************************** **********************************************
#include<iostream.h>
#include<iomanip>
#include<fstream> //For input data file.
using namespace std;


int main()
{
float side; // 1st input data field on each record: must be >=0
float area; // 2nd input data filed on each record: must be >=0
ifstream inFile; // Data file: each record shows side


//Attempt to open the input data file
inFile.open("sidearea.dat");
if(!inFile) // If file can't be found (we're in a fail state):
{
cout<<("Unable to open input file, program abnormally ended\n");
return 1; // Terminate program early, with return code=1:
}

//Get first pair of input data values for side and area, then echo print:
inFile>>side>>area;
cout<<"Record1:Side is"<<side<<"and area is"<<area<<endl;

//Check 1st record for I/O errors, then for valid data values:
;if(!inFile)
{
cout<<"I/O Error on input file, program abnormanlly ended\n";
return 1;
}
else
{
if(side<0)
cout<<"Warning side is invalid, must be = or > 0"<<endl;
if(area=(side*side))
cout<<"Warning area is invalid, must not be = to side square"<<endl;
}

//Get second pair of input data values for side and area
inFile>>side>>area;
cout<<"Record2:Side is:<<side<<and area is<<area<<endl;

//Check 2nd record for I/O errors, then for valid data values:
;if(inFile)
{
cout<<("I/O Error on input file, program abnormally ended");
return 1;
}
else
{
if(side<0)
cout<<"Warning side is invalid, must be = or > 0"<<endl;
if(area=(side*side))
cout<<"I/O Error on input file, program abnormally ended"<<endl;
}

//Terminate program normally:
cout<<"No I/O Errors in input file, pgm. terminated normally"<<endl;
return 0;
}
If this was copied directly, I would check this line:
//Check 1st record for I/O errors, then for valid data values:
;if(!inFile)
the 'if' statement has a ';' in front of it - that shouldn't be there.
Feb 20 '07 #2
Banfa
9,065 Expert Mod 8TB
What sicarie says is a minor error that is probably not stopping program compilation.

The "New line in constant" error is nearly always the result of failing to put the terminating " on a string constant.

In our case it happens on the cout line
Expand|Select|Wrap|Line Numbers
  1. //Get second pair of input data values for side and area
  2. inFile>>side>>area;
  3. cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
  4.  
where you appear to have missed out several "
Feb 20 '07 #3
sicarie
4,677 Expert Mod 4TB
What sicarie says is a minor error that is probably not stopping program compilation.

The "New line in constant" error is nearly always the result of failing to put the terminating " on a string constant.

In our case it happens on the cout line
Expand|Select|Wrap|Line Numbers
  1. //Get second pair of input data values for side and area
  2. inFile>>side>>area;
  3. cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
  4.  
where you appear to have missed out several "
Oh dang. I was thinking that couldn't just be it, but I missed that several times. Thanks, Banfa!
Feb 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Charles Erwin | last post by:
Is there any way, upon scanning in a file line by line to avoid missing the last line if there is not a newline character (aka you have to hit return on the last line of input in your file). I was...
20
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The...
3
by: Jacob Bensabat | last post by:
Hi I am trying to do the following template <class X> class CA { public: X m_a; X m_b; X Get(X& a,X& b)
6
by: Leo R | last post by:
Hi all, If an error occurs in an aspx-page, you can configure the web.config in a way that the user automatically navigates to a certain page (e.g. error.aspx). My question: is it possible to...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
13
by: albert_reade | last post by:
Could someone help me figure out why this error keeps occuring thanks for the help. error: cc FordFulkerson.c FordFulkerson.c:117:2: warning: no newline at end of file Code: #include...
17
by: pbd22 | last post by:
hi. i keep getting this error. as i understand it, my xml isn't formatted correctly. the online errata suggests the standard formatting to solve this problem: element (tab) (tab) element
11
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const...
3
by: Sajeena | last post by:
I have used smtp mail scripts <?php function authgMail($from, $namefrom, $to, $nameto, $subject, $message) { $smtpServer = "192.168.xxx.xxx"; //ip address of the mail server. This can also be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.