| | |
Remove exclamation marks form a text file and add to vector
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 27
Reputation:
Solved Threads: 0
i want to read words form a text file and remove the comars and fullstops and then put the single word to a vector. but when i try the method below i get an error can some one please help me.
C++ Syntax (Toggle Plain Text)
char delim[100]=",.`~!@#$%^&*()_+=-{}][:';?><|"; ifstream fileOne("file.txt"); string fileWord; while ( fileOne>> fileWord ) { for(unsigned int a=0; fileWord.size ();a++) { for(unsigned int b=0;b<100;b++) { if (delim[b]=fileWord[b]) fileWord.erase)(i); } } fileOneVector.push_back( fileWord); }
C++ Syntax (Toggle Plain Text)
if (delim[b]=fileWord[b])
Firstly Assignment "=" is not equal to Equal to "==".
C++ Syntax (Toggle Plain Text)
fileWord.erase)(i);
C++ Syntax (Toggle Plain Text)
for(unsigned int a=0; fileWord.size ();a++)
C++ Syntax (Toggle Plain Text)
for(unsigned int a=0;a< fileWord.size ();a++)
Another code improvment would be .
C++ Syntax (Toggle Plain Text)
char delim[]=",.`~!@#$%^&*()_+=-{}][:';?><|";
[/code]
C++ Syntax (Toggle Plain Text)
while(delim[b]!=0) //................ b++
•
•
•
•
C++ Syntax (Toggle Plain Text)
if (delim[b]=fileWord[b])
Firstly Assignment "=" is not equal to Equal to "==".
if (delim[b]=fileWord[b]) then you're assigning the value at fileWord[b] to delim[b] , as a result the assignment operator always returns the assigned value what means that if the assigned value isn't NULL or 0 (it's the same
) the if statement will treat the expression as false , in any other case the expression will be evaluated as true
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Last edited by tux4life; May 9th, 2009 at 10:21 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
•
•
Join Date: May 2009
Posts: 27
Reputation:
Solved Threads: 0
yes so i can say that if the char is equal to ispuntc then remove the character
•
•
•
•
yes so i can say that if the char is equal to ispuntc then remove the character
- Declare a string (called 'result' for example) to store the 'stripped' string in.
- Just loop through the string (containing the punctuation marks) and every time you evaluate whether the character is a punctuation mark or not, if the character is not a punctuation mark, you add it to your 'result' string, after the loop has finished you've a string which contains an 'exact' copy of the other one, but without the punctuation marks

To repeat what I've already said: the
strtok function might be a lot easier for you, but it's your choice
Last edited by tux4life; May 9th, 2009 at 11:20 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
•
•
Join Date: May 2009
Posts: 27
Reputation:
Solved Threads: 0
•
•
•
•
Yes you can, but there's an easier way:
- Declare a string (called 'result' for example) to store the 'stripped' string in.
- Just loop through the string (containing the punctuation marks) and every time you evaluate whether the character is a punctuation mark or not, if the character is not a punctuation mark, you add it to your 'result' string, after the loop has finished you've a string which contains an 'exact' copy of the other one, but without the punctuation marks
To repeat what I've already said: thestrtokfunction might be a lot easier for you, but it's your choice
could be be kindful to show me the sample code using strtok
![]() |
Other Threads in the C++ Forum
- Previous Thread: Run time stack overflow error help
- Next Thread: A Matrix calculator crash help please
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






