473,699 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to read this string

hi,

i'm trying to get a board with relays working under c++, i have a sample
code in visual basic to compose a string that is send to the serial port
but i am confused how to translate it to a c++ string
here is the vb code:

messagestring = Chr$(13) & Chr$(address) & "S6" & Chr$(checksum)

where adress is an integer from 1 to 255 and checksum is also an integer

how does this string look like? can anyone help?

thanx

marco
Jul 22 '05 #1
2 1394
marco wrote:
i'm trying to get a board with relays working under c++, i have a sample
code in visual basic to compose a string that is send to the serial port
but i am confused how to translate it to a c++ string
here is the vb code:

messagestring = Chr$(13) & Chr$(address) & "S6" & Chr$(checksum)

where adress is an integer from 1 to 255 and checksum is also an integer

how does this string look like? can anyone help?


Try

std::ostringstr eam os;
os << '\r' << (unsigned char)address << "S6" << checksum;
std::string str_to_output(o s.str());

and if you need the const char*, use

str_to_output.c _str()

HTH

Victor

P.S. AFAIK, Chr$(13) is the "carriage return", and that's why I used \r
in the output statement. It makes it a bit more portable, although you
could just as well use (char)13 .
Jul 22 '05 #2
After some experimenting everything works, thanx

marco

Victor Bazarov wrote:
marco wrote:
i'm trying to get a board with relays working under c++, i have a sample
code in visual basic to compose a string that is send to the serial port
but i am confused how to translate it to a c++ string
here is the vb code:

messagestring = Chr$(13) & Chr$(address) & "S6" & Chr$(checksum)

where adress is an integer from 1 to 255 and checksum is also an integer

how does this string look like? can anyone help?

Try

std::ostringstr eam os;
os << '\r' << (unsigned char)address << "S6" << checksum;
std::string str_to_output(o s.str());

and if you need the const char*, use

str_to_output.c _str()

HTH

Victor

P.S. AFAIK, Chr$(13) is the "carriage return", and that's why I used \r
in the output statement. It makes it a bit more portable, although you
could just as well use (char)13 .

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
13304
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; char c; std::string str;
9
7910
by: John Howard | last post by:
How can I read a text file that is on a UNIX server in VB.Net? Please keep it simple. Thanks, John
5
7535
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in EPay_Batch_Table Where File_Status=2? How to read multiple files and 1 file at a time, through a loop?
3
1808
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a new seek item in the textbox after I searched for an item and click the seek button.. it seems it is doing nothing. And also... what code can I use to genereate a messagebox message when a seek item is not at all in the CSV file?
6
32911
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line). Is there some way to burst read the whole file and later "extract" each line? Thanks in advance, Thomas Kowalski
6
5711
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a * vector<string>. Now, use istringstream to read read each line * from the vector a word at a time.
0
3865
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the string. write method should take a string. seek should take a number and return nuthing. use three member variables a buffer itself as a string, read_position, write_position. use >>, << methods. I have tried this code but i need full...
5
11266
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a couple areas that have ASCII text that I need to extract. At the end of the 2580 bytes, I can read the report like a standard text file. It should have CR/LF at the end of each line. What is the best way for me to read this report using C#. It is...
2
5344
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the db or save string to the db I don't want to have to copy the string to a file to use the WritePrivateProfileString and GetPrivateProfileString. Is there a way around this instead of writing my own class to operate on a string or stream ???
3
5887
by: maneshborase | last post by:
Hi friends, I am facing one serious problem in my application. I am trying to open dicom image file (.dcm) has size around 400 MB. But I am getting and unhandy exceptions, Some time, {System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2361
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.