visual c ++ studio windows窗体应用程序中的字符串流 [英] String stream in visual c++ studio windows forms app

查看:198
本文介绍了visual c ++ studio windows窗体应用程序中的字符串流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows窗体,读取字符串时有点迷失。



我有一个文本文件,读成字符串:

String ^ TextString = this-> textBox1-> Text;



现在我想一次读取一个这个字符串。它应该填充未定义的整数。我想一次选择每个输入,用空格或逗号分隔并且

a)检查它是否是整数

b)如果是int然后通过发送到函数库来做一些事情:store(x);



1.是否可以在visual c ++中完成所有操作或者我是否需要转换为std字符串? (我真的不想混合在同一个文件中)



2.如果我必须使用std,这是对的吗? :



 字符串 ^ TextString =   - > textBox1->文字;  //  找到的字符串 


int_separator< int> sep( ); // 定义分离的可能性
tokenizer< int_separator< INT> >标记(TextString,sep); // 标记字符串
BOOST_FOREACH( const string& num,tokens) // 每个字符串值发送到商店功能
{
store(num);
}





您是否看到了清洁的方式,而没有将标准c ++与视觉混合?听到你的想法,我非常感激。感谢您的阅读和任何回复。

解决方案

我发现我可以更轻松地使用它,修改为我的字符串:



 std :: string token,text( 这里:是:一些:文本); 
std :: istringstream iss(text); // 流式传输字符串文本
(getline(iss,token,' :')) // 获取行,分成令牌
{
store(token);
}
{

}





然后我需要以某种方式转换我的String ^ TextString to std :: string,并将其替换为示例text字符串。有什么想法吗?



****************************** *********************************************

对任何有同样问题的人:



http://www.daniweb.com/software-development/cpp/threads/27905/using-stringstream-for-tokenizing-a-string [ ^ ]


I''m working in windows forms and am a bit lost with reading a string.

I have a text file which is read into a string:
String ^ TextString = this->textBox1->Text;

Now I want to read this string one number at a time. It should be filled with an undefined amount of integers. I want to select each input at a time, seperated by either a space or comma and
a) check whether it is an integer or not
b) if it is an int then do some stuff to it via sending it off to function store: store( x );

1. Is it possible to do this all in visual c++ or do i need to convert to std string? (I dont really want to mix in the same file)

2. If I have to use std, is this right? :

String ^ TextString = this->textBox1->Text;  // string found


int_separator<int> sep(", "); // defines the seperation possibilities
tokenizer< int_separator<int> > tokens(TextString, sep); // tokenizes the string
BOOST_FOREACH (const string& num, tokens) // for each string value send into store function
{
   store( num );
}



Do you see a ''cleaner'' way, without mixing standard c++ with visual? I''d very much appreciate to hear your thoughts. Thank you for reading, and for any responses.

解决方案

I found I could more easily use this, modified to my string:

std::string token, text("Here:is:some:text"); 
std::istringstream iss(text); // streams the string text
while ( getline(iss, token, ':') ) // gets the line, seperates into "tokens"
{
    store(token);
}
{
					
}



But then I need to somehow convert my String^ TextString to a std::string and replace this with the examples "text" string. Any ideas how?

***************************************************************************
To any who have the same problem:

http://www.daniweb.com/software-development/cpp/threads/27905/using-stringstream-for-tokenizing-a-string[^]


这篇关于visual c ++ studio windows窗体应用程序中的字符串流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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