473,657 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string troubles

1 New Member
Hi All -
is this allowed in c++? it gives an access violation in Microsoft Visual C++.

int main()
{
char* c = "Hello There!";
c[0] = 'J';

return 0;
}

is that because of windows or am i just writing bad code? just learning c++.

Thanks!
Oct 11 '05 #1
3 1509
scanf
2 New Member
The reason your codes doesn't work is that
you used a char pointer that points to data segment then you tried to change the datasegment ,which you are not allowed to at all!

LOOK:
char*cp="Hello, World!";

Now cp points to a string in the data segment,which the programmer doesn't have to change....
Dec 6 '06 #2
Ganon11
3,652 Recognized Expert Specialist
Why not just use std::string instead of a pointer character array?
Dec 6 '06 #3
thefarmer
55 New Member
hi there,

actually like what gannon said you can used a simple string to this, and it may become more easy to read :
int main()
{
string MyString;
MyString = " Hello There";
cout << MyString <<end1;
return 0;
}

by this you can easily visuallized the output ok


regards,
Dec 7 '06 #4

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

Similar topics

0
1963
by: lmckaha | last post by:
Hi, Mysql version: 3.23.49 Solaris version: 2.7 gcc compiler version: 2.95.2 Python : 2.2.2 I'm evaluating the C and C++ API to decide which one to bye but I have many troubles.
3
1453
by: stanlo | last post by:
hi to everyone, this is still a follow up of my project ,mathematical expression.this project is meant to evaluate mathemtical expressions with oparators,+,-,*,/.more than two operands can be done, eg it should be able to do,1+9-45*7/12,or 4* 5+6*21.from reading and help from you i have been able to write the program.but my problem is to process the string of the input.i.e given for example an input string, 12+6*65/7, you know i have to...
18
7817
by: Metro12 | last post by:
In the <basic_string.h>, I find the implementation of these two functions. But I can't understand the difference between them. Please give me some help! //basic_string::c_str() const _CharT* c_str() const { // MT: This assumes concurrent writes are OK. size_type __n = this->size(); traits_type::assign(_M_data(), _Rep::_S_terminal);
7
6490
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me where I can look up explaination on the String.Format, the format string part like "("{0:.#0}". What's the trailing 0 and what is that "0:" means? I assume the "#" is the place holder character for th value obtain after the comma in the code. ...
0
1485
by: Michal | last post by:
I have troubles with instaling .Net Framework 2.0 (Beta 2 - 2.0.50215). The main instalation went just fine, troubles begin with my attemt to run aspnet_regiss.exe -i. Asp.Net is instaled into IIS as it should be, sites are working just fine. The only problem is thet this instalation did not create the AspNet_WebAdmin folder in /inetpub/wwwroot, thus the WebAdmin is not instaled in IIS and I cannot administer my sites. I read in official...
8
1743
by: merrittr | last post by:
I have been having troubles getting "string" input pushed on to the stack in the assn1. The funny thing is I can push a literal on no problem so push("push i 0"); push("push i 1"); push("add"); works fine however
0
1448
by: JohnIdol | last post by:
VC++6 to VC++2003 - linking troubles -------------------------------------------------------------------------------- Hi All, I successfully ported an application from VC++6 to VS2003. Solved compiling issues but now I am sticking with serious Linking troubles. I got a bunch of:
9
15727
by: thijs.braem | last post by:
Hi everyone, I'm having quite some troubles trying to convert Unicode to String (for use in psycopg, which apparently doesn't know how to cope with unicode strings). The error I keep having is something like this: ERREUR: Séquence d'octets invalide pour le codage «UTF8» : 0xe02063 (sorry, locale is french, it means "byte sequence invalid for encoding
1
1660
by: Pegasus | last post by:
Good morning, I'm Filippo Battaglia. We're porting Apache STDCXX under Nanodesktop. We are trying to make nd compatible also with C++ and not only with C. Unfortunately, we're finding different technical troubles in the compilation. So, can anyone of the developers tell with me ? So, I can solve the troubles step by step and I can obtain a working version of the library.
4
18690
by: kpalakode | last post by:
Hi, I am supposed to write a program that would identify whether a word is a palindrome string or not. I am having troubles with the spacing and punctuations. my code compiles and runs fine except if i have space or any punctuations in between the words it doesnt work. can anyone help me out please? here is my code int main() { queue <string> Q; stack <string> S;
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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
7327
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
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
5632
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
4152
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...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
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.