Иван Бишевац Иван Бишевац - 2 months ago 8
C++ Question

#include skipped when looking for precompiled header use -- unexpected end of file while looking for precompiled header

I have some code but it wan't compile. I can't go further with this example because this error raises every time I try to debug.
Note: I am Java programmer, and this message in VS is strange and I coudn't find what is problem. Can someone explain me what this error mean?

Here is code:

zadatak.cpp:

// zadatak.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "String.h"
#include <iostream>
using namespace std;

void main()
{
String s1(20),s2(20);
cout<<"Unesi prvi string."<<endl;
cin>>s1;
cout<<"Unesi drugi string."<<endl;
cin>>s2;
++s1;
s2++;
String s3(40);
s3=s1+s2;
cout<<"Treci string: "<<s3<<endl;
}


String.cpp:

#include "String.h"
#include <iostream>
using namespace std;
#include <string.h>

String::String(void)
:duzina(0)
{
niz=new char[duzina];
}

String::String(int br)
:duzina(br)
{
this->niz=new char[duzina];
}

String::~String(void)
{
delete [] niz;
}

String::String(String& s)
:duzina(s.duzina)
{
this->niz=new char[this->duzina];
for(int i=0; i<this->duzina; i++)
this->niz[i]=s.niz[i];
}

void String::nadjiPocetak(char rec[])
{
int poc=0;
for(int i=0; i<this->duzina; i++)
{
int duz=0;
if(this->niz[i]==rec[0])
{
int l=strlen(rec);
for(int j=0; j<l; j++)
if(this->niz[i+j]==rec[j])
duz+=1;
}
if(duz==strlen(rec))
poc=i;
}
if(poc==0)
cout<<"U stringu ne postoji zadati string."<<endl;
else
cout<<"Pocetak je na poziciji: "<<poc+1<<endl;
}

/*void String::ucitaj()
{
cout<<"Unesi string"<<endl;
cin>>this->niz;
}

void String::prikazi()
{
cout<<"String: "<<this->niz<<endl;
}*/

String& String::operator+ (String s)
{
String *s1;
s1=new String(duzina+s.duzina);
strcpy(s1->niz,niz);
strcat(s1->niz,s.niz);
return *s1;
}

String& String::operator++ ()
{
if(niz[0]>='a' && niz[0]<='z')
niz[0]='A'+niz[0]-'a';
return *this;
}

String& String::operator++ (int n)
{
for(int i=0; i<duzina; i++)
if(niz[i]>='a' && niz[i]<='z')
niz[i]='A'+niz[i]-'a';
return *this;
}

String& String::operator= (String& s)
{
duzina=s.duzina;
delete [] niz;
niz=new char[duzina];
strcpy(niz,s.niz);
return *this;
}

istream& operator>> (istream& in, String& s)
{
in>>s.niz;
return in;
}

ostream& operator<< (ostream& out, String& s)
{
out<<s.niz;
return out;
}


String.h:

#pragma once
#include <iostream>
using namespace std;

class String
{
private:
int duzina;
char* niz;
public:
String(void);
String(int br);
~String(void);
String(String& s);
int vratiDuzinu() {return this->duzina;}
void nadjiPocetak(char rec[]);
//void ucitaj();
//void prikazi();
String& operator+ (String s);
String& operator++ ();
String& operator++ (int n);
String& operator= (String& s);
friend istream& operator>> (istream& in, String& s);
friend ostream& operator<< (ostream& out, String& s);
};


Error that Visual Studio gives in output is:


1>------ Build started: Project: zadatak, Configuration: Debug Win32------

1>Build started 12/13/2011 02:44:50 AM.

1>InitializeBuildStatus:

1> Touching "Debug\zadatak.unsuccessfulbuild".

1>ClCompile:

1> All outputs are up-to-date.

1> zadatak.cpp

1> String.cpp

1>c:\users\ivo\documents\visual studio 2010\projects\zadatak\zadatak\string.cpp(1): warning C4627: '#include "String.h"': skipped when looking for precompiled header use

1> Add directive to 'StdAfx.h' or rebuild precompiled header

1>c:\users\ivo\documents\visual studio 2010\projects\zadatak\zadatak\string.cpp(2): warning C4627: '#include ': skipped when looking for precompiled header use

1> Add directive to 'StdAfx.h' or rebuild precompiled header

1>c:\users\ivo\documents\visual studio 2010\projects\zadatak\zadatak\string.cpp(4): warning C4627: '#include ': skipped when looking for precompiled header use

1> Add directive to 'StdAfx.h' or rebuild precompiled header

1>c:\users\ivo\documents\visual studio 2010\projects\zadatak\zadatak\string.cpp(108): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

1> Generating Code...

1>

1>Build FAILED.

1>

1>Time Elapsed 00:00:00.41

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Answer

You want

#include "stdafx.h"

in your String.cpp file, as with all .cpp files.

Comments