strcpy aaarrrrgggghhhh

This is a discussion on strcpy aaarrrrgggghhhh within the C++ Programming forums, part of the General Programming Boards category; Tokenise line from file into vector with the following and am trying to copy vector values to variables - have ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    24

    strcpy aaarrrrgggghhhh

    Tokenise line from file into vector with the following and am trying to copy vector values to variables - have tried EVERYTHING c_str()
    And have NO idea what is happening. Have noted all that have tried in below code. Any ideas??? The error msg is:
    cannot convert std::string to char* strcpy(char*,const char*)



    Code:
    void Tokenize(const string& str,
                          vector<string>& tokens,
                          const string& delimiters = "/n")
    {
        // Skip delimiters at beginning.
        string::size_type lastPos = str.find_first_not_of(delimiters, 0);
        // Find first "non-delimiter".
        string::size_type pos     = str.find_first_of(delimiters, lastPos);
    
        while (string::npos != pos || string::npos != lastPos)
        {
            // Found a token, add it to the vector.
            tokens.push_back(str.substr(lastPos, pos - lastPos));
            // Skip delimiters.  Note the "not_of"
            lastPos = str.find_first_not_of(delimiters, pos);
            // Find next "non-delimiter"
            pos = str.find_first_of(delimiters, lastPos);
        }
    }
    
    
    
    void loadTeams(char *line,string countryName,string code)
    {   
    	
    	string temp;
    	vector<string> teamTokens;
    	std::vector<string>::const_iterator p;
    	Tokenize(line, teamTokens,"|");
    	p=teamTokens.begin();
    	
    	
    	
    This compiles but doesnt work 
            Team* pTeam1 = new Team();
            pTeam1->setCountry(teamTokens[0]);
            pTeam1->setCountryCode(teamTokens[1]);
    
    	for(p=teamTokens.begin();p!=teamTokens.end();p++)
    	{
      
      This compiles but doesnt work   
       	   countryName=p[0];
       	   code=p[1];
       	   
    This doesnt compile    
                    strcpy(countryName,*p);
    
       	   
            }
       
    	
    	
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >void loadTeams(char *line,string countryName,string code)

    To return values in strings, pass them by reference:
    void loadTeams(char *line,string &countryName,string &code)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 08:42 AM
  2. Strcpy
    By Godders_2k in forum C Programming
    Replies: 17
    Last Post: 12-12-2007, 11:34 AM
  3. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 05:14 PM
  4. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 10:00 PM
  5. strcpy
    By Luigi in forum C++ Programming
    Replies: 17
    Last Post: 02-16-2003, 03:11 PM

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