473,405 Members | 2,210 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,405 software developers and data experts.

Getting numbers out of a string.

Hello,

I am using the Linux command "du -sb /root/" to get the number of bytes of the folder root. This of course returns something like:

1775440949 /root/

the number of bytes changes. How can I get C++ to take the string with "1775440949 /root/" in it a just get the numbers and put them into a separate string.

Thanks
Jan 26 '08 #1
5 4489
Ganon11
3,652 Expert 2GB
I think you should be able to use a stringstream for this.
Jan 26 '08 #2
Thankyou :)

Oh one other question. The string goes onto two lines like:

"42342423
<blank>"

how do I just get the first line?

Thanks
Jan 26 '08 #3
hsn
237 100+
for your first question to get a number out of a string use the following code
string str="123";
int size=str.size();
int sum;
for(int i=0; i<size; i++)
sum= (sum*10) str[i]-'0';

by using this code you will be able to transfer the number.

for your 2nd question
use the function getline();
string str="123\n";
string str2;
getline(str,str2);
by that str2 = "123";

good luck and i hope i was helpful

regards
hsn
Jan 26 '08 #4
WOW Thanks!

Thanks alot for your help guys!
Jan 26 '08 #5
woops!

Had a bit of a problem...

cannot convert ‘std::string’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’

Any ideas?
Jan 26 '08 #6

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

Similar topics

1
by: Tan Thuan Seah | last post by:
Hi all, I have a string with several numbers in it. The numbers each can be up to 14 characters.(i.e ---------12345---------1234, where - represents spaces). Is there any way to retrieve the...
5
by: Yoshitha | last post by:
Hi I am working on a web project. I have a InstallerClass in my project. While making setup ( using web setup template) for this web application, I have added a userinterface with 4...
2
by: Gidi | last post by:
hello, i have a datagrid and i want to deal with the string that enter on a currentCell after each KeyPress and data entering, the problem is that while i'm still at the same cell i get that the...
6
by: Matthias S. | last post by:
Hi, I'm pretty sure this is as easy as it gets, but I couldn't find anything in the documentation. I'd like to change the string representation of an int so that the numbers get padded with...
4
by: Mr. x | last post by:
Hello, I have declared in my program (*.aspx) something like this : <%@ Page Language="VB" Debug="true" %> .... <% dim current_view_page current_view_page = "1"
0
by: manicmax | last post by:
Hey I have a question for u I am taking connection string from IIS like this readonly string dataSource3 =ConfigurationManager.ConnectionStrings.ConnectionString; and using this dataSource3 ...
4
by: beginers of c | last post by:
hai friends see i have to get numbers in this manner 3 4 5 6 7 8 9 ok.And also my numbers should not be larger than 9.so for each number the condition has to be checked if it's great than 9 ,...
1
by: mcmahon | last post by:
Hi, I keep getting the error " Object reference not set to an instance of an object." in relation to the line : selA = CType(lstStudents.Items(r.Index), String) Any advice/help? ...
1
by: prasanna ganesh | last post by:
why i'm getting lang.string.NumberFormatException for input string ""please help me to find solution
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.