473,395 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

atoi does not work converting my cstring vector into ints.... why?

I have saved the contents of an int vector to a txt file and the numerical data was converted into a c-string. Nov
I need to import and read the contents back into my program but I have not been able to convert c-string numerical data back into ints. Can you help me out? Please....thank you.
Feb 18 '15 #1
1 1275
weaknessforcats
9,208 Expert Mod 8TB
Use a stringstream.

Expand|Select|Wrap|Line Numbers
  1. char* cstring = "1234";
  2.     stringstream ss;
  3.     ss << cstring;
  4.     int fetch;
  5.     ss >> fetch;
  6.     cout << fetch << endl;
The cstring represents the char string in your text file. Just read the file and use the insertion operator to push the chsr data into the stringstream ss. Then simply use the extraction operator to pull the char out and convert it to an int.

You can add your own insertion/extraction operators so you can handle your own class types in the same manner as above.
Feb 18 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: cv | last post by:
Hello All, I have used MultipartRequest like the following to upload images. MultipartRequest multi = new MultipartRequest(request, "../webapps/coreprogram/dealerlogos", 1024 * 1024); It...
7
by: hellwolf | last post by:
Hi,everyone.Because of my English level,I will try to use code to explain where I confused. //list of code: #include <iostream> #include <algorithm> #include <vector> class A{ static int...
4
by: Field | last post by:
Hi, the following snippet shows once executed this output: 2 2 I'd have rather expected this output: 2 10
4
by: Das | last post by:
Hi, I have made an application in ASP.net with C#. The application works fine with localhost. I have uploaded the site. I'm using web user controls in the form. but some of the button do not work...
10
by: Jim Langston | last post by:
Someone is working on some code, and during the iteration of a vector may delete an element and push_back a new one. I was thinking that this may invalidate the iteration iterator, but in my test...
1
by: Newbie in ChiTown | last post by:
Here's my code: I am using MS Access and I am trying to update a table (InvoiceDetails) with data input by the user on a form. However, it does not update nor does it give me an error message. ...
11
by: Jim | last post by:
Hi, I want to schedule a Python program that reads the command line for input. However, when adding an argument to the command line Python will not pick it up when using Windows scheduled...
3
by: tezu | last post by:
Hi all, ' How can i convert a cstring to unsigned short Thanks in advance :)
3
by: david sherman | last post by:
Does software converting excel to access with financial functions exist? I need to take several fixed income portfolio run manually from excel and create a database. The excel relies heavily on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...

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.