| View previous topic :: View next topic |
| Author |
Message |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Fri Dec 26, 2008 5:01 pm Post subject: [C++] While loops and filters |
|
|
Hey guys,
The book I'm learning from demonstrate the use of while loops with filters by compiling this code:
| Code: | #include <iostream>
#include <stdio.h>
using namespace std;
#define NEWLINE 'endl'
void main()
{
char c;
int linenum = 1;
std::cout << std::dec << linenum << ": ";
while ((c = getchar()) != EOF) {
if (c == NEWLINE) {
linenum++;
std::cout << NEWLINE << std::dec << linenum << ": ";
} else
putchar(c);
}
} |
and using this filter "linenum <linenum.cpp> linemun.txt" to write a number at the begining of each line and saving it as a new txt file.
I had to manipulate the code to compile with VCpp6 since the book using a different compiler, other than that they're the same and I had no problem compiling it, but when I'm runnig the exe file and typing the filter all I get is an echo of the filter..
Why isnt working?
_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++ |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Dec 26, 2008 6:03 pm Post subject: |
|
|
| '\n'... std::endl is not type char and 'endl' is not a single character...
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Fri Dec 26, 2008 7:26 pm Post subject: |
|
|
| Code: |
using namespace std;
|
Use that so you won't have to put "std::" in every std function.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Dec 26, 2008 8:02 pm Post subject: |
|
|
He is...
| Quote: | #include <iostream>
#include <stdio.h>
using namespace std; |
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Fri Dec 26, 2008 8:23 pm Post subject: |
|
|
| Oh didn't see it, I was just looking at the main code.
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
|
| Back to top |
|
 |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Sat Dec 27, 2008 8:44 am Post subject: |
|
|
Thanks guys =]]
_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++ |
|
| Back to top |
|
 |
|