PDA

Click to See Complete Forum and Search --> : Simple C++ error but i don't konw whats going on...newbie


struntz
Dec 10th, 2000, 01:19 AM
Hello everyone...
im' currenlty reading this book....
and its called thinking in C++

well the problem is,
look at this code..

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <conio.h>
using namespace std;
int main() {
vector<string> v;
ifstream in("FillVector.cpp");
string line;
while(getline(in,line))
v.push_back(line);
for(int i = 0; i < v.size(); i++)
cout << ": " << v[i] << endl;
getch();
return 0; }

i get an error that says....

c:\my documents\c++programs\fillvectandwhitesapces.cpp: In function `int main()':
c:\my documents\c++programs\fillvectandwhitesapces.cpp:16: implicit declaration of function `int getchar(...)'


and i also tried other forms like getchar() and using differnet things but still i get an error, like on somes, it says directory wasn't found...

so what am i doing wrong?

the code works fine until i try and put the last piece of code in so u have to press a button for it to EXIT,and this is console of coures....

if u know whats going on, please explain it :D

THanks for listening!:)

HarryW
Dec 10th, 2000, 01:40 AM
It works fine on mine (once I put the [i] that's missing back in of course ;)).

Are you using VC++ 6? Try going to Build -> Clean and try compiling it again. If that doesn't work, try it in a new project. I find that sometimes it just gets itself messed up.

struntz
Dec 10th, 2000, 10:15 AM
Hey when u said when i placed the [i] back in of course, what do u mean?
what am i missing?
and no i'm using DevC++

HarryW
Dec 10th, 2000, 10:38 AM
Hehe, well it's happened again look :) When you write the i in brackets like [i] the forum code sees it as an italics tag, so it gets removed and text after it gets changed to italic. It's better to use x or j instead of i when you post.

The code is fine in VC++ 6 anyway. Try copying the code and making a new .cpp file with the same code in, and try to compile that, see if you get the same errors.

struntz
Dec 10th, 2000, 12:51 PM
Okay i get the same error can u tell me another #include and functiont hat will work rather then chget()?

maybe it just doesn't except that or somthing?::confused::

HarryW
Dec 10th, 2000, 10:48 PM
No idea I'm afraid.