Help with string code

My error : Undefined first referenced
symbol in file
main /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/crt1.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 This program prompts the user to enter a word, phrase, or sentence and determines whether the input string is a palindrome or not.

#include<vector>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std; 
void toUpper(string & str, string & str1);
void removeNonAlphabets(string & str, string & str1);
bool isPalindrome(string &obj);

int main()
{
	string str, upperstr, alphastr;
	cout<< "Enter input to see if it is a palindrome" << endl;
	getline(cin, str);

cout<<"original input str contains" <<endl;
cout<<" "<< str <<endl;
toUpper(str, upperstr);
cout<<"after conversion to uppercase,input str becomes:"<<endl;
cout<<" "<<upperstr<<endl;
if(isPalindrome(alphastr))
	cout<<endl<<alphastr<<" is a palindrome!"<<endl;
else
	cout<<endl<<alphastr<<" is not a palindrome!"<<endl;
cout<<endl;
return 0;
}
void toUpper(string &str, string & upperstr)
{	
	int s = str.length();
	for(int i=0;i<s;i++)
	upperstr.push_back(toupper(str[i]));
}
void removeNonAlphabets(string &str, string &alphastr)
{
	int s=str.length();
	for(int i =0;i<s;i++)
	if(isalpha(str[i]))
	alphastr.push_back(str[i]);
}
bool isPalindrome(string &str)
{
	int s = str.length();
	for(int i=0;i<s/2;i++)
	if(str[i]!=str[s-i-1])
	return false;
	return true;
}
Last edited on
Solaris; good for you.

Anyway, line 23 has an extra " in it and it all goes wrong from there.
that didn't change the errors i have =/
void toUpper(string &obj1 str, string &obj2 str);

This makes no sense at all.

Your code also contains a number of other compilation errors. Is you compiler giving you no warnings or error messages about them?
Last edited on
I've made several changes, but idk what kind of error this is, no matter what i do, that is all I keep on getting !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<vector>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std; 
void toUpper(string & str, string & str1);
void removeNonAlphabets(string & str, string & str1);
bool isPalindrome(string &obj);

int main()
{
	string str, upperstr, alphastr;
	cout<< "Enter input to see if it is a palindrome" << endl;
	getline(cin, str);

cout<<"original input str contains" <<endl;
cout<<" "<< str <<endl;
toUpper(str, upperstr);
cout<<"after conversion to uppercase,input str becomes:"<<endl;
cout<<" "<<upperstr<<endl;
if(isPalindrome(alphastr))
	cout<<endl<<alphastr<<" is a palindrome!"<<endl;
else
	cout<<endl<<alphastr<<" is not a palindrome!"<<endl;
cout<<endl;
return 0;
}
void toUpper(string &str, string & upperstr)
{	
	int s = str.length();
	for(int i=0;i<s;i++)
	upperstr.push_back(toupper(str[i]));
}
void removeNonAlphabets(string &str, string &alphastr)
{
	int s=str.length();
	for(int i =0;i<s;i++)
	if(isalpha(str[i]))
	alphastr.push_back(str[i]);
}
bool isPalindrome(string &str)
{
	int s = str.length();
	for(int i=0;i<s/2;i++)
	if(str[i]!=str[s-i-1])
	return false;
	return true;
}
Last edited on
why does this keep coming up "Undefined first referenced
symbol in file
main /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/crt1.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status"

Please help =/
Please, I really don't even know what this error means.
Hey, when I run in cpp 4.9 compiler, it runs fine.
However, when I fill in AGTT for example, (which is obviously not a palindrome), it says its a palindrome:P
im using unix, so im not sure why this one isn't running and am getting those wierd errors, someone please help!! due tomorrow! =[
Since I am having no problems, I think its a GCC error. Have you tried updating to the latest GCC version?

Maybe this is interesting for you?
http://stackoverflow.com/questions/662904/unix-symbol-referencing-error
Last edited on
Topic archived. No new replies allowed.