473,378 Members | 1,454 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,378 software developers and data experts.

string::assign for int type?

name & line are string type;
age is int type.

Expand|Select|Wrap|Line Numbers
  1. size_t found_2=line.find("\s", found_1);    
  2. name.assign(line,found_1,found_2);
  3.  
  4. size_t found_3=line.find("\s", found_2);
  5. age.assign(line,found_2,found_3);
when i debug, msvc told me assign is a function for string only. how can i do the same job for int type?
Mar 28 '08 #1
4 2149
mac11
256 100+
name & line are string type;
age is int type.

Expand|Select|Wrap|Line Numbers
  1. size_t found_2=line.find("\s", found_1);    
  2. name.assign(line,found_1,found_2);
  3.  
  4. size_t found_3=line.find("\s", found_2);
  5. age.assign(line,found_2,found_3);
when i debug, msvc told me assign is a function for string only. how can i do the same job for int type?
I'm not sure what your intent is here. Are you extracting a number (as text) from the string 'line' and you want to store the value in the int 'age'?

If so you'll have to convert the substring to int first. If this is not what your intending then I need more clarification.
Mar 28 '08 #2
I'm not sure what your intent is here. Are you extracting a number (as text) from the string 'line' and you want to store the value in the int 'age'?

If so you'll have to convert the substring to int first. If this is not what your intending then I need more clarification.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     string str1[3];
  10.     string aray[3];
  11.     string str1[0]={123450};
  12.     string str1[1]={123451};
  13.     string str1[2]={123452};
  14.  
  15.     for (int i=0; i<2; i++)
  16.     {
  17.         cout << str1[i] << endl;
  18.     }
  19.  
  20.     for(int j=0; j<100; j++)
  21.     {
  22.         int aray[j] = atoi(str1[j].c_str());
  23.     }
  24.  
  25.     for (int i=0; i<2; i++)
  26.     {
  27.         cout << aray[i] << endl;
  28.     }
  29. }
Yes, i want to do the job u said. but what you mean by convert the substring to int first ?? is that what i did in the above?
What's wrong with that code? Many errors
Mar 28 '08 #3
i solved the problem on my own !! thx u all

some definition problem in the codees...
Mar 28 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
I hope you found out that string only uses the char data type.

wstring uses wchar_t and these are the only teo types u you can use in basic_string<>.
Mar 29 '08 #5

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

Similar topics

9
by: David Carter-Hitchin | last post by:
Hi, I'm not very experienced with c++ so I'm sure this is something obvious that is easily solved, but for the life of me I can't seem to figure it out. I'd be very grateful for some...
3
by: Makiyo | last post by:
how do u do something like this char x; x = "hello"; I got an error, but is there a way I can do it without using pointer? thx ; )
2
by: zhengfish | last post by:
HI,all I have a class named CCC which have some members of std::string type. I declare a class pointer like this: CCC* ccc = new CCC( xml_input ); then I send the ccc to another module with...
3
by: Alex K. | last post by:
Hi all I need a string type with only three possible values: let's say "A", "B", "C". In other words, I need something like enum but of string type: enum MyStrings { sA = "A", sB = "B", sC...
1
by: Mike | last post by:
Hi, I'm passing a JSON-encoded string to json_decode() and am expecting its output to be an object type, but am getting a string type instead. How can I return an object? In the docs, the...
1
by: mathewgk80 | last post by:
Hi all, I would like to convert dataset type to string type... i am using asp.net,c#.net and sql server.. Please help me. Regards, Mathew
1
by: kenneth6 | last post by:
ctype.h: toupper(c), tolower(c): change case of char isalphanum(c), isalpha(c), isdigit(c), ispunct(c), isspace(c), iscntrl(c), islower(c), isupper(c): boolean checks on type of char i know...
1
by: kenneth6 | last post by:
I am writing sth about data in string type in console mode. now, I transform it to Windows Form Application, i know managed type should be used here instead of the unmanaged type. should I change...
6
by: SchoolOfLife | last post by:
Does an object in C++ of std::string type terminates with null character? The charater string literals in C++ (to maintain backward compatibility with C) end with a null character. Is this same with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.