Solved

VC++ syntax errors

Posted on 2004-09-15
14
575 Views
Last Modified: 2012-06-21
Hello, I have a program working fine on UNIX, but not on my new VC++.Net (Standard Edition). I have syntax error when i compile it. The messagea are:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2059: syntax error : ':'

Anyone knows the solutions ? Thank you

Here is my code:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdio>


//using namespace std;

const int MaxSize=1024;

//////////////////////////////////
//
// struct for reference data
//
//////////////////////////////////
typedef struct
{
 char keyData[10];
 char valueData[20];
} KeyRef;


//////////////////////////////////////////
// function to lookup value by key
//////////////////////////////////////////
char* findKeyValue(KeyRef* ref, char* k){
      
      for (int i=0;i<MaxSize;i++){
            if (!strcmp(ref[i].keyData,k))
                  return ref[i].valueData;
      }
      return "None";
};


///////////////////////////////
//
// main
//
///////////////////////////////
main(int arc, char *arv[])
{

      ifstream fin("c:\\test\api test\fin.txt");
      ofstream fout("c:\\test\api test\fout.txt");
char row_read[512];
char row_elem[10][50];

ifstream fin2("c:\\test\api test\frefer.txt");
ofstream fout2("refer_out.txt");
KeyRef refer_data[MaxSize];
char refer_read[MaxSize];
char refer_row_elem[2][MaxSize];
int i=0,j=0,k=0;

//////////////////////////////////////////
// read refer file into struct of array
//////////////////////////////////////////
while( fin2.getline( refer_read,MaxSize ))
{
      char *tok = strtok(refer_read,",");
      while( tok != NULL) {
            strcpy(refer_row_elem[j],tok);
            tok= strtok(NULL,",");
            j++;
      }
      strcpy(refer_data[k].keyData, refer_row_elem[0]);
      strcpy(refer_data[k].valueData, refer_row_elem[1]);
      j=0;
      k++;
}

/////////////////////////////////////////////////
// output refer file , review data only
/////////////////////////////////////////////////
//for (int q=0;q<k;q++){
//       fout2 << setw(10) << refer_data[q].keyData << setw(10) << refer_data[q].valueData << endl;
//}


///////////////////////////////////////////////////////////////////
// for each line of file  
// assume there are 5 collums in each row in file fin.txt
///////////////////////////////////////////////////////////////////
while( fin.getline( row_read, sizeof( row_read ) ) )
{
      //////////////////////////////////////////
      // parse string with ","
      //////////////////////////////////////////
      char *token = strtok( row_read, "," );
      while( token != NULL )
      {
        /* While there are tokens in "string" */
        strcpy(row_elem[i], token );
        /* Get next token: */
        token = strtok( NULL, "," );
        i++;
      }

      //////////////////////////////////////////////////////////////////////
      // get reference value by looking at key in reference file
      //////////////////////////////////////////////////////////////////////
      char* valueFound;
      valueFound = findKeyValue(refer_data, row_elem[0]);
      cout << " value found - " << valueFound << endl;

      //////////////////////////////////////////////////////////////////////
      // output to file, first colmn replaced with value from reference file
      //////////////////////////////////////////////////////////////////////
      fout<<setw(10)      << valueFound
          << setw(10) << row_elem[4]
          <<setw(10)      << row_elem[3]
          <<setw(10)      << row_elem[2]
          <<setw(10)      << row_elem[1]
          <<endl;

      i=0;
}

return 0;
}
0
Comment
Question by:justinY
14 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 12069787
Can you post your version of cstdio?  I have not seen this error using that file.  Line 30 (though somethimes the line numbers are not accurate) in my file is:

    using ::sscanf; using ::tmpfile; using ::tmpnam;

I copied your source file as posted (uncommenting the 'using namespace std;') and it compiles fine for me.
0
 

Author Comment

by:justinY
ID: 12069880
Here is the cstdio file

// cstdio standard header
#pragma once
#ifndef _CSTDIO_
#define _CSTDIO_
#include <yvals.h>

#ifdef _STD_USING
#undef _STD_USING
#include <stdio.h>
#define _STD_USING

#else /* _STD_USING */
#include <stdio.h>

#if _GLOBAL_USING
_STD_BEGIN
using ::size_t; using ::fpos_t; using ::FILE;
using ::clearerr; using ::fclose; using ::feof;
using ::ferror; using ::fflush; using ::fgetc;
using ::fgetpos; using ::fgets; using ::fopen;
using ::fprintf; using ::fputc; using ::fputs;
using ::fread; using ::freopen; using ::fscanf;
using ::fseek; using ::fsetpos; using ::ftell;
using ::fwrite; using ::getc; using ::getchar;
using ::gets; using ::perror;
using ::putc; using ::putchar;
using ::printf; using ::puts; using ::remove;
using ::rename; using ::rewind; using ::scanf;
using ::setbuf; using ::setvbuf; using ::sprintf;
using ::sscanf; using ::tmpfile; using ::tmpnam;
using ::ungetc; using ::vfprintf; using ::vprintf;
using ::vsprintf;
_STD_END
#endif /* _GLOBAL_USING */

#endif /* _STD_USING */
#endif /* _CSTDIO_ */

/*
 * Copyright (c) 1992-2002 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
 V3.13:0009 */
0
 
LVL 19

Expert Comment

by:drichards
ID: 12070650
Hmm, that's the same as my file.  You're probably going to have to experiment a bit to figure this one out since it would appear to be an environment problem.

HOWEVER, just remove '#include <cstdio>' as you are not using it for anything - I removed it and your file still compiles.
0
 

Author Comment

by:justinY
ID: 12077097
I have tried so many times, still cannot identify where the problem is. So anybody wants to jump in ? thanks
0
 
LVL 19

Expert Comment

by:drichards
ID: 12077393
Does removing cstdio from your #includes not solve your problem?

If you really need cstdio for some reason, have you tried systematically looking for the problem?  I would start by making a local copy of ctsdio and using it - use quotes instead of brackets to make it search local directory first.

    #include "cstdio"

Then make a cpp file with only an empty main function (other than the mandatory return).  Try commenting out the offending line.  Also try commenting out all the other includes outside of cstdio.  If the error goes away, add back includes until the error returns.  Keep experimenting until you pinpoint the problem.

Another thing to check is your projects settings.  Did you change any of the deafult settings?  Did you create the project with the Wizard or by hand?

Unless someone else is experiencing the same problem, I doubt anyone will be able to really help you.  
0
 

Author Comment

by:justinY
ID: 12079050
Hi, I tried almost everything. Still not working. I post my log file here see if you can pinpoint anything from it.


Build Log      ------- Build started: Project: cliff, Configuration: Debug|Win32 -------

 Command Lines      This edition of Visual C++ does not support the optimizing compiler.
Creating temporary file "c:\test\cliff\Debug\RSP00003F.rsp" with contents
[
/D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MLd /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /TC
.\cvt.C
]
Creating command line "cl.exe @c:\test\cliff\Debug\RSP00003F.rsp /nologo"
 Output Window      Compiling...
cvt.C
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cerrno(18) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cerrno(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(19) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(19) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(19) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(20) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(20) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(20) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(20) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(20) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(20) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(21) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(21) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(21) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(21) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(21) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(21) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(22) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(22) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(22) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(22) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(22) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(22) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(23) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(23) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(23) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(23) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(23) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(23) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(24) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(24) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(24) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(24) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(24) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(24) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(25) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(25) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(25) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(25) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(26) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(26) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(26) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(26) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(27) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(27) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(27) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(27) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(27) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(27) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(28) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(28) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(28) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(28) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(28) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(28) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(29) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(29) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(29) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(29) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(29) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(29) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(30) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(31) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(31) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(31) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(31) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(31) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(31) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(32) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(32) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(19) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(19) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(19) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib(19) : fatal error C1003: error count exceeds 100; stopping compilation
 Results      Build log was saved at "file://c:\test\cliff\Debug\BuildLog.htm"
cliff - 102 error(s), 0 warning(s)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:justinY
ID: 12079126
I got it fixed.
the answer is in MSND website. the file extention must be .cpp, not .c.
0
 

Expert Comment

by:sharda_arvind
ID: 12307634
Hello dear

I check ur code..it is fine..i test it by taking a console application in .net frame work.it is compiling fine..i have just removed the comment on line

//using namespace std

if u want i can send u the compiled code
0
 

Expert Comment

by:mikeant78
ID: 12352340

Why don't you try this set of includes instead?

#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
0
 

Author Comment

by:justinY
ID: 12352440
Hi guys

I got it fixed.
the answer is in MSND website. the file extention must be .cpp, NOT .c.
I had .C before. After I changed .c to .cpp, It works fine. Thanks
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 12411643
The question has been PAQ'd and the 500 points have been refunded.
RomMod
Community Support Moderator
0
 
LVL 1

Expert Comment

by:megaone
ID: 15009358
Has been answered ... ==> WHERE ???
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now