Parse Error

This is a discussion on Parse Error within the C++ Programming forums, part of the General Programming Boards category; Probably just some silly error I've overlooked, but even after looking back over the code several times I don't see ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    Parse Error

    Probably just some silly error I've overlooked, but even after looking back over the code several times I don't see what's wrong.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    void letters(string test, int plus, int strsize);
    
    int main(){
    
    string test="A string";
    int strsize=test.size();
    
    letters(string test, int plus, int strsize);
    
    return 0;
    }
    
    void letters(string test, int plus, int strsize){
    	for(plus=0; plus<strsize; plus++){
    	cout<<test[plus];
    	}
    }

    Error:
    Code:
    /home/cerin/string.cpp: In function `int main()':
    /home/cerin/string.cpp:12: error: parse error before `,' token
    My computer is awesome.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Well, you are declaring a function inside main, instead of calling it.

    Code:
    letters(test, plus, strsize);
    You also need to define plus
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Also in your letters function you don't have to pass the 'plus' integer into it, you could initialise it, and the other limit inside the function itself, like so:

    Code:
    void letters(string test)
    {
    	int strsize = test.size();
    
    	for(int i=0; i<strsize; i++) // I replaced your plusses with a i-s
    	{
    		cout<<test[i];
    	}
    }
    It makes the function's parameters less confusing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 03:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21