且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

visual c ++ studio windows窗体应用程序中的字符串流

更新时间:2023-12-06 13:47:22

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



 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[^]