StringStream到Character的转换. [英] StringStream to Character conversion.

查看:71
本文介绍了StringStream到Character的转换.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件abc.txt,需要逐行读取并从中提取令牌.

I have a file abc.txt which i need to read line by line and extract tokens from it.

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




在上面的代码中,我从用户提交的文件x中获取输入字符串流,并在s1中使用它.此后,我多次使用循环来读取一行.现在我需要在strtok函数的参数中使用等于第一行字符串的s1的值. strtok不接受.我将s1字符串流转换为s2字符串.即使这样,strtok也不会接受s2.

错误是;




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 ;

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'

推荐答案

您正在论坛中充斥着一些问题,您可以通过一些基础研究和一些艰苦的研究轻松地回答自己.掌握一本不错的C ++书籍并学习该语言,以便您至少对一些简单的事情有合理的了解,例如读取文件,处理字符串等.
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.


这篇关于StringStream到Character的转换.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆