Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a file abc.txt which i need to read line by line and extract tokens from it.

C++
while( getline( x, s1 ) )
{
string s2=s1.str()
strtok( s2, seps );					
}



In the code above i am taking an input stringstream from the file x submitted by the user and using it in s1. thereafter i am using a loop as many times i get to read a line. now i need to use the value of s1 which equals string of first line, in the strtok function's parameter. strtok does not accepts this. i converted s1 stringstream to s2 string. even then strtok is not accepting s2.

The error is ;

VB
hw2.cpp:57: error: request for member 'str' in 'st', which is of non-class type 'char [1]'
hw2.cpp:66: error: cannot convert 'std::string' to 'char*' for argument '1' to 'char* strtok(char*, const char*)'
hw2.cpp:59: warning: unused variable 'cstr1'
Posted

1 solution

You are flooding the forum with questions which you could easily answer yourself with a bit of basic research and some hard study. Get hold of a decent C++ book and study the language so you have at least a reasonable understanding of simple things like reading files, handling strings, etc.
 
Share this answer
 
Comments
typedefcoder 23-Sep-11 15:21pm    
I never meant to flood the forum . The thing is i have been stuck on this since over 8 hours. I just required a hint.
Richard MacCutchan 24-Sep-11 4:39am    
I have given you more than hints, I have pointed you towards answers but your understanding of C++ seems to be rather basic. Try reading beyond the first line of the answers you are given and take some of the advice. Spend some time studying classes, objects, strings, file handling etc, before posting what is essentially the same question again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900